How do I generate dynamic variable name in controller and pass the variable to ng-repeat?
Asked
Active
Viewed 253 times
1
-
see https://stackoverflow.com/questions/32470928/angular-formly-adding-form-fields-dynamically-on-user-click/35603088#35603088 – Hadi J Jun 04 '17 at 10:34
-
Thank you so much. I will check. – user1636102 Jun 04 '17 at 10:38
1 Answers
-1
You can use math.random, here I'm adding 30 random numbers where each value can have a possibility of being from 0 to 30.
$scope.randomArrayNumbers = [];
for (i = 0, len = 30; i<len; ++i){
$scope.randomArrayNumbers.push(Math.floor(Math.random() * 30) + 1);
}
console.log($scope.randomArrayNumbers);

Dilshan Liyanage
- 4,440
- 2
- 31
- 33
-
Hi., Here you are generating random numbers. But my case, I need to generate dynamic variable name and pass to ng-repeat. – user1636102 Jun 04 '17 at 11:32
-
Sorry if it wasn't clear, but now all you have to do is
- {{random}}
-
-
I want to append child node to parent node when clicking parent node. There is many parent nodes. If i click another parent node, I can able to append the child for corresponding parent node. But what happened, both the child nodes has updating since I am using same scope variable. It is not dynamic. For this case I need to create dynamic variable name and it should work for particular child. – user1636102 Jun 04 '17 at 11:44