angular.js - $scope. Can variable names be declared dynamically?
漂亮男人
漂亮男人 2017-05-16 13:19:50
0
3
748

Can angular variable names be dynamically generated?
For example, like this

   for (var w = 0; w < source.length; i++) {
            ($scope.chartdata + w) = rows;
  }
  

I want to dynamically generate the variable name on the left, but it doesn’t seem to work. Does anyone have a good way to solve dynamic naming?

漂亮男人
漂亮男人

reply all(3)
Peter_Zhu

$scope["chartdata"+w] = rows;

为情所困
$scope[chartdata + w] = rows; 
滿天的星座

Why not try the object method?

for (var w = 0; w < source.length; i++) {
    $scope.chartdata[w] = rows;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template