简体   繁体   中英

How to add Dynamic Scope variables to a for loop in angularjs?

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?

尝试这个

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM