简体   繁体   English

ng-init和ng-repeat是否正确绑定?

[英]Does ng-init and ng-repeat bind properly?

<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 上面的代码有2个数组

Alist which has field name, the value of name is a field in Blist , lets suppose value of field name in Alist is text. Alist其中有字段名称,名称的值是在外地Blist ,让现场的名字假设值Alist是文本。

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. 当我直接编写y.text而不是y.test123 ,该值将同时显示在屏幕上以及选项值中,但是当我尝试在test123获取该值然后编写上述代码时,两个值均不会显示在选项值中也不会显示在屏幕上。

  1. If you call y.test123 you should have a attribute inside the BLits array. 如果调用y.test123,则在BLits数组中应该有一个属性。

    ex: BLits = [test123:'sampletext'] 例如:BLits = [test123:'sampletext']

  2. data-ng-init="test123=x.name;" data-ng-init =“ test123 = x.name;” this code should work and if you use {{test123}} it will populate the x.name value. 该代码应该可以工作,如果您使用{{test123}},它将填充x.name值。

so I assume you don't have a attribute called test123 inside BLits array and so it does not populate any value. 因此,我假设您在BLits数组中没有名为test123的属性,因此它不会填充任何值。 instead it will give a error on your console. 相反,它将在您的控制台上显示错误。

如果我们简单地将方括号中的test123写入对象数组,就可以解决上述问题

y[test123]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM