Reputation: 10586
I am trying to create dynamic scope variable.
Here is the json object:
{
"status": true,
"res": {
"call": [
{
"percent": 100,
"name": "150+"
}
],
"stores": [
{
"percent": 100,
"name": "150+"
}
],
"web": [
{
"percent": 21,
"name": "120-150"
},
{
"percent": 79,
"name": "150+"
}
]
}
}
Here is the code what i am trying to do:
for(keys in jsonObject.res){
$scope.<SomeString+keys> = 'something';
}
Please suggest me what would be the better way to achieve this?
Assume jsonObject is the object what i have specified above
Upvotes: 2
Views: 4724
Reputation: 1458
$parse Converts Angular expression into a function with .
for(key in jsonObject.res){
$parse('someObj.key').assign($scope, 'somevalue')
$scope.apply()
}
Upvotes: 2