Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How to execute a function on "Paste" event in input in Angular 1.1.5? I know there is a ng-change directive for input. But it fires each time the input changes, I need only once on initial paste.

Use-case: I have a URL input. I want to execute a function after user pastes the URL. User also can manually enter the URL and execute the function by pressing Enter.

--

Update: Since Angular 1.2.0, ngPaste is a native directive.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
178 views
Welcome To Ask or Share your Answers For Others

1 Answer

Since Angular 1.2.0 there is an ngPaste directive. Use the following way:

<input type='text' ng-paste='handlePaste($event)'>

To pass the value straightaway, use:

<input type='text' ng-paste='handlePaste($event.clipboardData.getData('text/plain'))'>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...