bsr
bsr

Reputation: 58682

Angular JS: scope and ng-repeat inside a directive

I am trying to write custom directive. This is a fork from an example by Andy Joslin.

Please see the code http://plnkr.co/edit/jXfr6P?p=preview

I could pass the selection method to the first child scope, but not further. I know ng-repeat create child scopes, and the original example updates the model correctly. But, not sure how to call the function.

Click on Apparel -> sel = Apparel ==> works
Click on Mens Shirts  -> sel = Apparel ==> Not OK (needs to be Mens Shirts )
Click on Mens Special Shirts -> sel = Apparel ==> works Not OK (needs to be Mens Special Shirts)
...
Click on Boats -> sel = Boats ==> works

Upvotes: 1

Views: 2808

Answers (1)

matys84pl
matys84pl

Reputation: 8334

I've managed to fix your example. The key to finding the solution was to change the directive scope to:

 scope: {
      tree: '=ngModel',
      selection:'=selection' // changed & to =
    }

as you have to pass the selection function for each tree and choice this way:

selection="selection" // was selection="selection(val)"

See my forked plunker: http://plnkr.co/edit/2tal6V?p=preview

Upvotes: 3

Related Questions