Rendy Rendy - 1 year ago 69
AngularJS Question

Map depends on dynamic variable

I have following hardcoded map:

$scope.lists = {
test1: [
{ name: 'My Name' }
test2: [
{ name: 'My Second Name' }

$scope.selectedList = "test1";

Then inside my pug/html file:

div(ng-repeat="list in lists.selectedList")

What I need is I want to have array to be selected depend on var of
. Am I able to do that in AngularJS?

Answer Source

You can use square-bracket syntax in angular attributes:

 div(ng-repeat="list in lists[selectedList]")