Skip to content Skip to sidebar Skip to footer

Dynamic Ng-init Variable - Angularjs

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

Solution 1:

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

Post a Comment for "Dynamic Ng-init Variable - Angularjs"