Dennis
Dennis

Reputation: 25

Use variable inside ng-repeat

I'm trying to find a way to insert my variable(s) into ng-repeat, see examples below for explanation.

controller.js

$scope.firstParams = $stateParams.firstId;

template.html

<span style="margin-left:3px;" ng-repeat="list in user.userlists.{{firstParams}}"></span>

ng-repeat example is just for displaying purpose

Basically what I want to do is having my ng-repeat fetch the params via $scope.firstParams and have it like so: ng-repeat="list in user.userlists.gameboy" if the params would be "gameboy".

I tried a bunch of filter:Options with no success.

Upvotes: 2

Views: 555

Answers (2)

charlietfl
charlietfl

Reputation: 171700

In javascript you use [] notation for variable property names

Try

ng-repeat="list in user.userlists[firstParams]"

Demo Link - http://jsfiddle.net/tk11wz7j/

Upvotes: 3

matt.j.crawford
matt.j.crawford

Reputation: 392

the {{value}} is for rendering a value, what you need is a filter for example

list in user.userlists | filter: firstParams

Upvotes: 0

Related Questions