动态NG-初始化变量 - Angularjs [英] Dynamic ng-init variable - Angularjs
问题描述
.coffee
@FooCtrl = ->
$scope.products = Product.query()
的.html
<div ng-repeat='product in products'>
<div ng-init='images_{{product.id}} = product.images' >
<div class='slideshow' ng-repeat='pic in images_{{product.id}}'>
<img ng-src='{{pic.url}}' />
</div>
</div>
我想要做像this.But NG-的init ='_图片{{product.id}}
抛出一些exception.Any补救或替代的解决方案为这个?
I wanna do like this.But ng-init='images_{{product.id}}'
is throwing some exception.Any remedy or alternate solution for this?
推荐答案
你正在做的可能还不如NG-INIT采取标准的JavaScript前pression让 {{}} 工作方式code>是行不通的。
The way you are doing may not work as ng-init take standard Javascript expression so {{}}
would not work.
由于JavaScript对象只是一个key-value集合。您需要使用 []
标记访问动态属性,而不是上。
符号。
Since javascript objects are just a key-value collection. You need to access dynamic properties using []
notation instead on .
notation.
所以这
&LT; DIV NG-的init ='_图片{{product.id}} = product.images&GT;
变为
&LT; DIV NG-的init ='本[图片_+ this.product.id] = product.images'&GT;
请参阅这拨弄我创建
这篇关于动态NG-初始化变量 - Angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!