javascript - angularjs ngblur不生效 onblur生效,為什么?
問題描述
<input type='text'ng-model='$ctrl.replyString'>
這個input使用ng-blur是不會觸發(fā)的,但是直接DOM綁定onblur事件是會觸發(fā),為什么?
問題解答
回答1:你用的是1還是2如果是2的話,可以<input type='text' [(ngModel)]='myModel' (blur)='onBlurMethod()'>
export class AppComponent { myModel: any; constructor(){ this.myModel = ’123’; } onBlurMethod(){ alert(this.myModel) }}回答2:
angular1的ng-blur要通過指令才能使用,指令的作用其實就是將ng-blur綁定的事件應用到onblur事件
app.directive(’ngBlur’, [’$parse’, function($parse) { return function(scope, element, attr) { var fn = $parse(attr[’ngBlur’]); element.bind(’blur’, function(event) { scope.$apply(function() {fn(scope, {$event:event}); }); }); }}]);
相關文章:
1. mysql無法刪除字段(錯誤1091),但是對該字段設置主鍵后就可刪除,為什么?2. java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver發(fā)生異常。為什么?3. JavaScript在全局對象中聲明變量,會成為一個全局對象的同名屬性而在函數(shù)中聲明變量則不會,為什么?4. 簡單的Java示例以14個線程運行。為什么?5. java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver發(fā)生異常為什么?6. javascript - 求解答,koa-bodyparser獲取到的參數(shù)是空對象,為什么?????7. javascript - 最小函數(shù)準則 一個函數(shù)里只能干一件相關事情 為什么?真的有意義嗎?~8. html5 - 調試時,背景圖可以顯示;在真機上顯示不出來,為什么?9. javascript - map 渲染img標簽時,會出現(xiàn)圖片中間會以逗號分隔。是因為什么?10. python - flask post提交timestamp不能作為參數(shù),這是為什么?

網(wǎng)公網(wǎng)安備