[英]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?
您知道我可以使用 for 循环遍历变量名数组并将该值分配给作用域变量的最佳方法吗?
尝试这个
$scope['linkName'+i] = 'Some value';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.