search

Home  >  Q&A  >  body text

angular.js - $scope. Can variable names be declared dynamically?

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?

漂亮男人漂亮男人2754 days ago698

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-05-16 13:21:50

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

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:21:50

    $scope[chartdata + w] = rows; 

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 13:21:50

    Why not try the object method?

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

    reply
    0
  • Cancelreply