javascript - AngularJS ngblur wird nicht wirksam, aber onblur wird wirksam, warum?
淡淡烟草味
淡淡烟草味 2017-06-30 09:57:53
0
2
781
<input class="detail-reply"
        id="replyInput"
        type="text"
        ng-model="$ctrl.replyString">

Diese Eingabe nutzt das auszulösende ng-blur是不会触发的,但是直接DOM绑定onblur-Ereignis. Warum?

淡淡烟草味
淡淡烟草味

Antworte allen(2)
世界只因有你

你用的是1还是2如果是2的话,可以
<input type="text" [(ngModel)]="myModel" (blur)="onBlurMethod()">

export class AppComponent { 
  myModel: any;
  constructor(){
    this.myModel = '123';
  }
  onBlurMethod(){
   alert(this.myModel) 
  }
}
淡淡烟草味

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});
      });
    });
  }
}]);
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!