1

How can I do if I am trying to combine 2 string values? For example ng-repeat = "a in (name + 'List')". The name string value in this expression allList, jonnyList, henryList. How can I do that?

Example code:

<ul ng-repeat="a in name+List"> // i want if "name = 'all'", Return the values in allList.
    <li>{{a}}</li>
</ul>
1
  • post a fiddle or add some dummy data here Commented Apr 24, 2017 at 12:51

2 Answers 2

4

You can create function, which will return desired array as $scope's corresponding property:

$scope.dynamicArray = function(name){
    return $scope[name + 'List'];
}

<ul ng-repeat="a in dynamicArray(name)">
    <li>{{a}}</li>
</ul>
Sign up to request clarification or add additional context in comments.

Comments

2

Define a scope method that adds the "List" and then use this method in ng-repeat

$scope.getList = function(name) {
   return $scope[name + "List"];
};

<ul ng-repeat="a in getList(name)">
    <li>{{a}}</li>
</ul>

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.