JPS
JPS

Reputation: 2760

Initializing variables that dynamically created inside ng-repeat

I need to create variables dynamically inside ng-repeat and initialize it using ng-init.

<div data-ng-repeat="r in ['first','second','third']" data-ng-init="{{'panel'+$index}}=true">
      {{'panel'+$index}} 
   </div>

The output of the above code is,

panel0
panel1
panel2

But I need the following output,

true
true
true

Here is the plunker.

Upvotes: 0

Views: 2825

Answers (1)

veljkoz
veljkoz

Reputation: 8514

Try putting your values as an array:

<div id="{{'panel'+$index}}" data-ng-repeat="r in ['first','second','third']" data-ng-init="t['panel'+$index]=true">
      {{t['panel'+$index]}} 
</div>

Upvotes: 1

Related Questions