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"

});
1

1 Answer 1

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];
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.