How to properly bind scope between directive and controller with angularJS

后端 未结 3 2011
耶瑟儿~
耶瑟儿~ 2021-02-02 13:32

I\'m trying to generate an n-level hierarchical unordered list with anugularJS, and have been able to successfully do so. But now, I\'m having scope issues between the directiv

3条回答
  •  死守一世寂寞
    2021-02-02 13:36

    Please have a look at this working fiddle, http://jsfiddle.net/eeuSv/

    What i did was to require the parent controller inside the navtree-node directive, and call a member function defined in that controller. The member function is setSelected. Please note that its this.setSelected and not $scope.setSelected. Then define a navtree-node scope method itemSelect. While you click on the anchor tags, it will call the itemSelect method on the navtree-node scope. This inturn will call the controllers member method setSelected passing the selected id.

    scope.itemSelect = function(id){ myGreatParentControler.setSelected(id) }

提交回复
热议问题