angular.js - How to connect a concatenated variable name after $scope in angularjs?
ringa_lee
ringa_lee 2017-05-15 16:55:12
0
4
703

Upload code:

for (var i = 1; i < 7; i++) {
    var res='res'+i;
    $scope.res=XXXX;
  };

The variable name is composed of the string res plus i, which is res1--res6; how to connect a concatenated variable name after $scope? $scope.res i or $scope[res i] will not work

Thanks for the answer: The final answer is that you cannot click. Connect variables

ringa_lee
ringa_lee

ringa_lee

reply all(4)
左手右手慢动作

$scope[res] = xxxxx;

黄舟

for (var i = 1; i < 7; i++) {

var res='res'+i;
$scope[res]=i;

}

我想大声告诉你

First of all, res should be an array,
$scope.res=[];

for (var i = 1; i < 7; i++) {
$scope.res.push('res'+i);
}

Probably written like this.

漂亮男人

$scope["res"+i] Just write it like this

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template