2

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

2

1 Answer 1

2

$parse Converts Angular expression into a function with .

for(key in jsonObject.res){
    $parse('someObj.key').assign($scope, 'somevalue')
    $scope.apply()
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.