[英]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.