4

I have directive with input

<input ng-model="inputModel" ng-disabled="ngDisabled || isLoading" value="{{value}}" type="{{type}}" placeholder="{{placeholder | translate}}">

I use this directive like this:

<input-ext type="'text'" name="email" ng-model="registerCtrl.email" ng-blur="registerCtrl.test()" required></input-ext>

I want to after blur inside my directive to executed blur in input-ext ... , for this example code in controller, how to make this ?

Random
  • 3,158
  • 1
  • 15
  • 25
Artur Kasperek
  • 565
  • 2
  • 5
  • 17

2 Answers2

17

On your link function you bind them

   link: function (scope, element, attrs) {
        element.bind('blur', function (e) {
             //do something
        });
   }
0
.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;
                });
            }
        }
    })

I dont known that You undestand me well, if user add to inputExt ng-blur and add to this atribiute some argument, function, this function should be executed when user go out from input in directive

Artur Kasperek
  • 565
  • 2
  • 5
  • 17