AngularJS: ngTransclude and ngRepeat access scope

We are now updating our application to Angular 1.3.0. However, we ran into several problems, most of which seem to boil down to ngTransclude behavior inside ngRepeat.

We have a directive that repeats a bunch of elements, with a container around them, but does not own the children of this container. For example, here is a simplified example:

<div ng-controller="myController"> There are {{items.length}} items. <div my-directive items="items"> This item name is {{item.name}} </div> </div> 

Inside the directive contains, among other things, <li ng-repeat="item in items" ng-transclude></li> .

Before the update, this worked fine. Duplicate, translated elements are in a region that inherits from the region created by ngRepeat. Starting with the update, the elements are in the area that is inherited from the controller, and as far as I can tell, there is no way to access the area created by ngRepeat.

Here are two examples of JS Bin:

How can I achieve old behavior or some similarity in Angular 1.3.0? If this is the intended behavior of ngTransclude, how can I repeat a bunch of child nodes without knowing what it is?

+5
source share
1 answer

https://github.com/angular/angular.js/issues/8182

It was decided for 1.3 that ng-trasclude would not pull the scale out of the directive. There’s a crawl on linked pages,

https://github.com/angular/angular.js/issues/7874 https://github.com/angular/angular.js/issues/7874#issuecomment-47647528

This is the expected behavior.

+3
source

Source: https://habr.com/ru/post/1204764/


All Articles