Kawa Saki Kawa Saki - 5 months ago 12
AngularJS Question

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";

Answer

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

Comments