我在自定义指令中使用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'
};
}
简单角度控制器:
var app = angular.module('ashtest', []);
app.controller('TopCtrl', ['$scope',
function($scope) {
$scope.obj = {
test: "Ashkan"
};
$scope.change = function() {
$scope.obj.test = "changedThis";
}
}
]);
答案 0 :(得分:4)
ngBlur:'&amp;',
解释:
What is the difference between '@' and '=' in directive scope in AngularJS?