在自定义指令中使用 ng-blur

Using ng-blur in custom directive

我在自定义指令中使用 ng-blur 时遇到问题。我想要的是能够制作一个组件,该组件可以处理发送到指令 ng-blur 属性中的任何类型的函数。

这是指令示例:

<az-dir ng-blur="change()" lid="test" ng-model="obj.test"></az-dir>

Javascript 指令

app.directive('azDir', azDir);
function azDir() {
  return {
    restrict: 'E',
    scope: {
      ngModel: '=',
      ngBlur: '=',
      lid: '@'
    },
    templateUrl: 'directive.html',
    replace: true,
    require: 'ngModel'
  };
}

简单angular控制器:

var app = angular.module('ashtest', []);

app.controller('TopCtrl', ['$scope',
  function($scope) {

    $scope.obj = {
      test: "Ashkan"
    };

    $scope.change = function() {
      $scope.obj.test = "changedThis";
    }


  }
]);

My Plunker Sample

ngBlur: '&',

解释于:

  1. "@"(文本绑定/单向绑定)
  2. "="(直接模型绑定/双向绑定)
  3. "&"(行为绑定/方法绑定)

What is the difference between '@' and '=' in directive scope in AngularJS?