1

I am building app where I want to dynamically create one array which I have to assign to dynamically created table using ng-repeat.
In my directive I have appended tr like :

 link: function (scope, elem, attrs) {
    $(elem).click(function () {
             var tmpl="<tr ng-repeat='orders in allCurrentTakeAwayOrder'>
                       </tr>";
    });
  }

and this is repeating multiple time on button click event.
I want to append a dynamic id to this <tr> as

 <tr ng-repeat='orders in allCurrentTakeAwayOrder"+scope.divId+"'>

and it is appending successfully.
But problem is that how can I append same id to that variable in controller, when assigning a data to that variable?

app.controller('orderController', function ($scope){ 

  $scope.allCurrentTakeAwayOrder **<i want to append that id here>**  ="data will be here to be display in table"

});
Rohit Ghotkar
  • 803
  • 5
  • 17
  • I refer you to a previous post which can assist with what you are trying to achieve: http://stackoverflow.com/questions/18875486/setting-dynamic-scope-variables-in-angularjs-scope-some-string – Conrad Lotz Oct 14 '16 at 10:11

1 Answers1

2

To append scope.divId to scope variable name, use a function with a property accessor:

<!-- replace with function
   <tr ng-repeat='orders in allCurrentTakeAwayOrder"+scope.divId+"'>
-->

<tr ng-repeat='orders in computedList()'>

JS

scope.computedList = function() {
    return scope["allCurrentTakeAwayOrder"+scope.divId];
};
georgeawg
  • 48,608
  • 13
  • 72
  • 95