0

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?

kispi
  • 185
  • 1
  • 12

1 Answers1

1

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'));
}
Chandru
  • 10,864
  • 6
  • 38
  • 53
  • Thank you. So the problem was, the moment ng-model is changed is coming after foo is called? – kispi Oct 30 '17 at 08:50