worldask
worldask

Reputation: 1837

How to pass arguments to an isolated scope when using & in custom directive?

I have a function in my controller scope

$scope.read = function(a, b, c){};

I've binded it to my custom directive

<dir read="read(a, b, c)"></dir>

And my custom directive

angular.module('app').directive('dir', function() {
  restrict: 'E',
  scope: {
    read: '&'
  },
  link: function() {
    read(a, b, c); 
  }
});

When I debuged it, all three arguments are undefined. How can I make it work?

Upvotes: 0

Views: 30

Answers (1)

Nikos Paraskevopoulos
Nikos Paraskevopoulos

Reputation: 40298

The way to call the function from the directive is:

link: function(scope, elem, attrs) {
    scope.read({a: your_a_argument, b: your_b_argument, c: your_c_argument});
}

Upvotes: 1

Related Questions