Login Or Sign up

Does ng-init and ng-repeat bind properly?

52 Views Asked by At
<tr data-ng-repeat="x in AList" data-ng-init="loopIndex=$index;">
<select data-ng-model='y.value' style="width:80%;margin-left:20px;" data-ng-change="filter()" data-ng-init="test123=x.name;">
<option data-ng-repeat="y in BList" value="{{y.test123}}">{{y.test123}}></option>

The above code has 2 arrays

Alist which has field name, the value of name is a field in Blist, lets suppose value of field name in Alist is text.

When I directly write y.text instead of y.test123, the value populates on the screen and also in option value, but when I try to fetch the value in test123 and then I write the above code, neither the value populates in option value nor it is displayed on the screen.

2

There are 2 best solutions below

6
Shashan Sooriyahetti On
  1. If you call y.test123 you should have a attribute inside the BLits array.

    ex: BLits = [test123:'sampletext']

  2. data-ng-init="test123=x.name;" this code should work and if you use {{test123}} it will populate the x.name value.

so I assume you don't have a attribute called test123 inside BLits array and so it does not populate any value. instead it will give a error on your console.

0
AudioBubble On

the above problem can be solved if we simply write test123 in square brackets, accessing array of objects

y[test123]