1

How do I generate dynamic variable name in controller and pass the variable to ng-repeat?

user1636102
  • 121
  • 4
  • 11

1 Answers1

-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}}
    – Dilshan Liyanage Jun 04 '17 at 11:35
  • Sorry. I think i am confusing you. I will explain. – user1636102 Jun 04 '17 at 11:39
  • 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