user1612293
user1612293

Reputation: 69

How to pass parameters from directive to controller?

I'm trying to pass from directive to controller a function with 1 param but it alerts undefined.

myApp.controller('MyController', function($scope, $window) {

    $scope.blabla = function(msg) { alert(msg) };
});

http://jsfiddle.net/72G3D/

Lol :).Thanks

Upvotes: 0

Views: 1304

Answers (1)

Ganaraj
Ganaraj

Reputation: 26841

You were passing a variable called hello instead of "hello"

Here is an updated fiddle which works.

http://jsfiddle.net/72G3D/1/

Here is the relevant part that changed

<div py="blabla('hello')">eqweq</div>

Notice the quotes around hello

Between you are not passing that function from the directive to the controller. You are in fact passing it the other way around (which is correct and fine ). If you are passing a function from directive to a controller there is something wrong there architecture wise.

Upvotes: 2

Related Questions