Dynamic ng-init variable - Angularjs

后端 未结 1 966
一生所求
一生所求 2021-01-06 12:09

.coffee

@FooCtrl = ->
  $scope.products = Product.query()

.html

相关标签:
1条回答
  • 2021-01-06 13:07

    The way you are doing may not work as ng-init take standard Javascript expression so {{}} would not work.

    Since javascript objects are just a key-value collection. You need to access dynamic properties using [] notation instead on . notation.

    So this

    <div ng-init='images_{{product.id}} = product.images >

    becomes

    <div ng-init='this["images_"+this.product.id] = product.images'>

    See this fiddle i created

    0 讨论(0)
提交回复
热议问题