How to dynamically add an ng-repeat attribute to an element

Is it possible to dynamically add an attribute ng-repeatto an element? If so, how?

EDIT

I tried to create a component that will use its own template inside it for each element in its list.

Example

<custom-component>
  <item-template>
    <span>{{item.name}}</span>
  <item-template>
<custom-component>

Then the result should be

<custom-component>
  <ul>
    <li ng-repeat="item in $ctrl.items">(the template)</li>
  </ul>
</custom-component>

So, I tried just setting innerHTML for ul to a string like this:

ul.innerHtml = "<li ng-repeat="item in $ctrl.items">{{item.name}}</li>"
+4
source share
1 answer

The solution will show an element that has ng-repeat depending on the condition, which you can change dynamically:

<div ng-switch="dynamicCondition">
    <div ng-switch-when="true" ng-repeat="item in items">Element which have ng-repeat</div>
    <div ng-switch-when="false">Element without ng-repeat</div>
</div>
+2
source

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


All Articles