angularjs - Passing a controller function between directives -


i have set of 2 directives call each other recursively render tree structure.

i need pass controller function reference directives in turn, need pass each other reference. seems work except parameters.

passing reference directive:

<item-list items="data" functionreference="controllerfunction(name)"></item-list> 

passing reference between directives:

<item-list items="item.children" functionreference="functionreference(name)"></item-list></li> 

calling function:

$scope.functionreference({name: name}); 

here's example (jsfiddle)

what proper way declare , pass function reference?

in itemlist template:

template: '<ul><item ng-repeat="item in items" item="item" functionreference="functionreference(name)' 

you reference function functionreference(name), can't call (you should calling functionreference({name:name}) instead.

so, changing template to:

tempate: '<ul><item ng-repeat="item in items" item="item" functionreference="functionreference({name: name})' 

it should work fine.

update:
same holds appended <li> in item directive:

<item-list items="item.children" functionreference="functionreference({name:name})"></item-list> // instead of: functionreference(name) 

see, also, updated demo.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -