Reputation: 45
Let's say for example, you have a .json file with "father": {"name":"Bob"}
and a javascript file that gets the data from it and stores it in an array called family.
{{family.father.name}}
would then print out the father's name on the html page.
Would it be possible to do something like:
In the javascript file:
$scope.member = "father";
In index.html:
{{family.{{member}}.name}}
// Is there some way to replace father with a variable
// from the javascript file? Just curious.
Upvotes: 0
Views: 98
Reputation: 17589
Using dictionary notation, yes
var member = 'father'
family[member].name === family.father.name
Or in angular
js:
$scope.member = 'father'
$scope.family = { 'father': { name : 'Bob' } }
html:
{{ family[member].name }}
Will output 'Bob'
Upvotes: 2