AngularJS Create a new area in a template?

using Symfony2.x, I have a vaulted loop through the data for some data, and I also have ng-repeat for similar elements (the difference is that these load in the background), but both have the same functionality. I have some odd functionality that happens in loop versions that work fine in ng-repeat versions. I have a feeling this is a problem with the area.

I read in the docs that ng-repeat will automatically create a new area for repeating elements, but of course this does not happen with the loop.

How to manually, and preferably exclusively in a template, call a new area for a repeating element?

+1
angularjs symfony
source share
1 answer

The easiest way is to add a directive for each element. This can be done in the template. Then the directive can request a new scope (via scope:true or scope:{} ), and each repeated element will receive a new scope associated with it.

You can create a directive for an element of type:

 <div mydirective></div> 

Then in your code define a directive:

 myApp.directive('mydirective',function(){ return { scope: true, link: function(scope, elem, attrs){ // do some scope / element stuff here } } }); 
+2
source share

All Articles