问题描述
如何在 Angular 1.1.5 的输入中对粘贴"事件执行函数?我知道有一个 ng-change
指令用于输入.但是每次输入更改时它都会触发,我只需要在初始粘贴时进行一次.
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.
用例:我有一个 URL 输入.我想在用户粘贴 URL 后执行一个函数.用户也可以手动输入 URL 并按 Enter 执行该功能.
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.
--
更新:从 Angular 1.2.0 开始,ngPaste 是一个原生指令.
Update: Since Angular 1.2.0, ngPaste is a native directive.
推荐答案
从 Angular 1.2.0 开始就有了 ngPaste 指令.使用以下方式:
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'))'>
这篇关于“粘贴"Angular 中的事件 [ngPaste]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!