动态NG-初始化变量 - Angularjs [英] Dynamic ng-init variable - Angularjs

查看:748
本文介绍了动态NG-初始化变量 - 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让 {{}} 是行不通的。

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; D​​IV NG-的init ='_图片{{product.id}} = product.images&GT;

变为

&LT; D​​IV NG-的init ='本[图片_+ this.product.id] = product.images'&GT;

请参阅拨弄我创建

这篇关于动态NG-初始化变量 - Angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆