Angular的输入字段上的ng-blur不起作用

sfl*_*che 8 javascript angularjs

好的,所以我很确定我错过了一些明显的东西,但我没有看到它.

我创建了一个小提琴,当输入框失去焦点时,我会认为它会抛出警告信息,但它不起作用,我不知道为什么.

当用户执行以下步骤时,我期待一条警告消息:

  1. 单击输入框
  2. 输入一些东西
  3. 单击输入框外部的某个位置

但这些步骤不会显示警告消息.

当然,有人知道我做错了什么......?

这是代码(与小提琴相同):

<div ng-app>
  <div ng-controller="MyCtrl">  
    <form name="myForm">
      <input type="text" ng-model="todoText" size="30"
         name="myInput" ng-blur="validate(myForm)">
    </form>
  </div>
</div>

function MyCtrl($scope) {
  $scope.validate = function(form) {
    alert('blur!');
  };
}
Run Code Online (Sandbox Code Playgroud)

Nix*_*Nix 5

它可能是您的 angular 版本。你的小提琴正在使用1.0.x 我更新你1.4.x并且它工作正常:

<div ng-app='myApp'>
  <div ng-controller="MyCtrl">  
  {{santity}}
    <form name="myForm">
      <input type="text" ng-model="todoText" size="30"
             name="myInput" ng-blur="validate(myForm)">
    </form>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

Javascript

angular.module('myApp', []);
angular.module('myApp').controller('MyCtrl', MyCtrl);

function MyCtrl($scope) {
 $scope.santity = 'Hello';
 $scope.validate = function(form) {
  alert('blur!');
 };
}
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/ncapito/LurjLvz7/6/