![](/img/trans.png)
[英]For ng-keyup unable to do event.preventDefault() and ng-keypress lagging behind a value for input type number in angular.js
[英]ng-keypress, ng-keyup, ng-keydown not firing
我在角度1.4.7中有這段代碼:
<input ng-keypress="console.log('press');" required="" class="form-control" ng-model="item" name="item" ng-disabled="reviewMode === 'REVIEW'" placeholder="Item">
console.log('press')不會在按下任何鍵時觸發。 我也嘗試使用keyup和keydown,它們也不起作用。
我知道一個元素需要具有ng-keypress的tabindex屬性才能工作,我嘗試添加該屬性,即使它是輸入元素也很難(仍然不起作用)。
我想念什么?
不能直接在HTML中使用console.log
,AngularJS會在函數范圍內查找。
看一下這個例子 。
ng-keypress
是內置的角度指令,用於執行范圍函數和表達式。 Angular不允許執行這樣的警報或控制台日志。 您需要創建一個作用域函數並將console.log()放入該函數中,以便執行控制台日志
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.