Aditya Sethi
Aditya Sethi

Reputation: 10586

Creating dynamic scope variables

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

Answers (1)

Kwaw Annor
Kwaw Annor

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

Related Questions