7PlusCoder
7PlusCoder

Reputation: 33

Dynamic index array angularJs

I have variable like below

$scope.priceOption = [];
$scope.priceOption['flip'] =            {
    dbvalue: "option:flip",
    caption:"反転図面の作成",          
    price:{TN:100,
           UR:200,
           HD:300}
};
$scope.priceOption['car'] =         {
    dbvalue: "option:car", 
    caption:"植栽・自動車・外構の追加", 
    price:{TN:100,
           UR:200,
           HD:300}
};
var price_type="HD";

How can I get price with dynamic price_type in HTML?

<label>{{priceOption['car'].price[price_type]}}円</label>

// expect value is 300円, if price_type = "HD";

Upvotes: 0

Views: 52

Answers (2)

Ravindra Miyani
Ravindra Miyani

Reputation: 370

You should use $scope.price_type="HD" instead of var price_type="HD" because you can not access javascript variable in view other than declared with $scope

Upvotes: 0

Episodex
Episodex

Reputation: 4559

Change var price_type="HD"; to $scope.price_type="HD";. The view doesn't see the variable you pass to binding.

Upvotes: 1

Related Questions