0

is it possible to concat for loop itteration value to scope variable in angular js?

$scope.rate1=220;
$scope.rate2=22123;
$scope.rate3=2223;
 ...
$scope.ratex=2223;

for(i=1;i<=x;i++)
{
alert($scope.rate.i);
alert($scope.rate[i]);
alert($scope.rate(i);
}
1
  • Why not simply use an array? Commented Jul 16, 2015 at 10:47

1 Answer 1

1

Please check working example : DEMO

Controller :

 $scope.rate1 = 220;
 $scope.rate2 = 22123;
 $scope.rate3 = 2223;

 for (var i = 1; i <= 3; i++) {
     alert($scope['rate' + i]);
 }
Sign up to request clarification or add additional context in comments.

2 Comments

hi i am very new to this page, i dont know how to accept it
i got only 2 reputation. after getting 15 only.. it ll be possible

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.