Let's say I have
<input type="text" ng-paste="foo(v)" ng-model="v">
and
$scope.foo = function(val) {
console.log(val);
}
I get 'undefined' on console.
I think it's because when the moment ng-paste is called, model is still 'undefined' and then pasted value is coming after.
How can I use pasted strings using ng-paste?
Try like this :
Angularjs :
template.html
<input type="text" ng-paste="foo($event)" ng-model="v">
controller.js
$scope.v = "";
$scope.foo = function(e) {
console.log(e.originalEvent.clipboardData.getData('text/plain'));
}
Angular 2
template.html
<input type="text" (paste)="foo($event)" [(ngModel)]="v">
component.ts
v: any;
foo(e) {
console.log(e.clipboardData.getData('text/plain'));
}