Dennis Dennis - 1 year ago 108
AngularJS Question

Use variable inside ng-repeat

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


$scope.firstParams = $stateParams.firstId;


<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've searched far and hopefully wide but i cant seem to find a solution that fits, i tried a bunch of filter:Options with no success.

Anyone got a solution for this? Much thanks in advantage!

Answer Source

In javascript you use [] notation for variable property names


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

Demo Link -

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download