Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I want to create dynamic scope variables. Here is a sample for loop that I created

for(var i=0; i<array.length; i++){ $scope.'linkName'+i = 'Some value'; // it should be like $scope.linkName1, $scope.linkName2, etc. }

The problem is that it doesn't allow for me to create it this way. Do you know the best way that I can use a for loop to loop through an array of variable names and assign that value to the scope variable?

share|improve this question
up vote 0 down vote accepted

Try this

$scope['linkName'+i] = 'Some value';

share|improve this answer
    
Thanks so much! Worked like a charm! – LadyT Aug 3 '15 at 19:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.