2

I am having problems with using ng-blur in a custom directive. What I want is to be able to make a component that can handle any type of function sent into the ng-blur attribute on the directive.

Here is the directive example:

<az-dir ng-blur="change()" lid="test" ng-model="obj.test"></az-dir>

Javascript directive

app.directive('azDir', azDir);
function azDir() {
  return {
    restrict: 'E',
    scope: {
      ngModel: '=',
      ngBlur: '=',
      lid: '@'
    },
    templateUrl: 'directive.html',
    replace: true,
    require: 'ngModel'
  };
}

Simple angular controller:

var app = angular.module('ashtest', []);

app.controller('TopCtrl', ['$scope',
  function($scope) {

    $scope.obj = {
      test: "Ashkan"
    };

    $scope.change = function() {
      $scope.obj.test = "changedThis";
    }


  }
]);

My Plunker Sample

J_P
  • 642
  • 1
  • 8
  • 23
Ashkan Hovold
  • 898
  • 2
  • 13
  • 28

1 Answers1

4

ngBlur: '&',

explaining in:

  1. "@" ( Text binding / one-way binding )
  2. "=" ( Direct model binding / two-way binding )
  3. "&" ( Behaviour binding / Method binding )

What is the difference between '@' and '=' in directive scope in AngularJS?

Community
  • 1
  • 1