How to get parent element inside ng-include when iterating in ng-repeat recursively

后端 未结 2 1093
轻奢々
轻奢々 2021-02-02 18:17

I made a recursive ng-repeat element, and trying to manipulate things has turned into a nightmare, because I don\'t have reference to the parent I\'m iterating over.

The

2条回答
  •  抹茶落季
    2021-02-02 18:27

    I would stay away from Angular's $parent and all the $scope creation and inheritance madness. What you need is to keep a reference to the parent object, not finding how many scopes are in-between ng-include's and ng-repeat's and juggling with $parent.$parent. My suggestion is to explicitly save references to the values you are interested in, just implement it yourself with custom logic. For example, if you want to expose a value from the parent ng-repeat to the child ng-repeat

    
    

    Then in your javascript code you can access all parents recursively

    function doSomething(value){
      parent1 = value._parent;
      parent2 = parent1._parent;
    }
    

    Same code with ng-include

提交回复
热议问题