search

Home  >  Q&A  >  body text

angular.js - How to connect a concatenated variable name after $scope in angularjs?

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_leeringa_lee2833 days ago710

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-05-15 16:57:12

    $scope[res] = xxxxx;

    reply
    0
  • 黄舟

    黄舟2017-05-15 16:57:12

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

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

    }

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-15 16:57:12

    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.

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-15 16:57:12

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

    reply
    0
  • Cancelreply