Javascript 如何捕捉angularJS指令中的模糊或聚焦事件
我有输入指令Javascript 如何捕捉angularJS指令中的模糊或聚焦事件,javascript,angularjs,angularjs-directive,Javascript,Angularjs,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=
<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>
我想在我的指令中执行模糊后,在输入ext中执行模糊,对于控制器中的示例代码,如何进行此操作?在链接函数上绑定它们
link: function (scope, element, attrs) {
element.bind('blur', function (e) {
//do something
});
}
我不知道你不理解我,如果用户添加到inputExt ng blur并添加到该命令中一些参数、函数,该函数应该在用户从input in指令中退出时执行显示该指令的JS。要触发模糊,你需要设置焦点。您可能需要$timeout才能将焦点设置在该点上。检查并最终确定。
.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;
});
}
}
})