[英]How to catch blur or focus event in angularJS directive
我有输入指令
<input ng-model="inputModel" ng-disabled="ngDisabled || isLoading" value="{{value}}" type="{{type}}" placeholder="{{placeholder | translate}}">
我像这样使用这个指令:
<input-ext type="'text'" name="email" ng-model="registerCtrl.email" ng-blur="registerCtrl.test()" required></input-ext>
我希望在我的指令内模糊后,在input-ext中执行模糊...,对于控制器中的这个示例代码,如何制作这个?
在链接功能上绑定它们
link: function (scope, element, attrs) {
element.bind('blur', function (e) {
//do something
});
}
.directive('inputExt', function() {
return {
restrict: 'E',
templateUrl: 'templates/inputExt3.html',
require: 'ngModel',
scope: {
'name' : '@',
'type' : '=',
'placeholder' : '=',
'value' : '=',
'ngDisabled': '=',
'isLoading' : '=',
'customStatus': '=',
'cutomStatusType': '=',
'test' : '&'
},
link: function($scope, element, attrs, ngModelCtrl) {
$scope.placeholder = $scope.placeholder == undefined ? $scope.name : $scope.placeholder;
$scope.$watch('inputModel', function() {
ngModelCtrl.$setViewValue($scope.inputModel);
});
ngModelCtrl.$parsers.push(function(viewValue) {
ngModelCtrl.$validate();
$scope.invalid = ngModelCtrl.$invalid;
$scope.error = ngModelCtrl.$error;
return viewValue;
});
}
}
})
我不知道你好不好看,如果用户添加到inputExt ng-blur并添加一个参数,函数,这个函数应该在用户从指令输入中执行时执行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.