我在自定义指令中使用 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 Controller :
var app = angular.module('ashtest', []);
app.controller('TopCtrl', ['$scope',
function($scope) {
$scope.obj = {
test: "Ashkan"
};
$scope.change = function() {
$scope.obj.test = "changedThis";
}
}
]);
最佳答案
ngBlur: '&',
解释:
- “@”(文本绑定(bind)/单向绑定(bind))
- "="(直接模型绑定(bind)/双向绑定(bind))
- “&”(行为绑定(bind)/方法绑定(bind))
What is the difference between '@' and '=' in directive scope in AngularJS?
关于angularjs - 在自定义指令中使用 ng-blur,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33798351/