1

I'm trying to create a simple category with items kind of setup, where the categories will be all my albums with all the tracks. I've tried to set it up like this:

enitoniApp.controller('musicItems', ['$scope', function ($scope) {
    $scope.albums = [
        {
            name: 'Over The Mountains',
            tracks: [
                {
                    name: 'Over The Mountains',
                    ref: 'otmt',
                    released: 0,
                    price: 0,
                },
                {
                    name: '!C3',
                    ref: 'ice',
                    released: 0,
                    price: 0,
                }
        ]
    }
    ]
}]);

and in the view:

<body>
    <div id="allMusic" ng-controller="musicItems">
        <div id="albums">
            <ul>
                <li ng-repeat="album in albums">
                    <div class="title">{{album.name}}</div>
                    <ul>
                        <li ng-repeat="track in albums.tracks">{{ track.name}}</li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</body>

The expected behaviour is that angular.js will repeat the li's inside the album li based on how many tracks, which in this case is two. However, I cannot get it to access the amount of array items inside tracks.

This is what I am trying to achieve:

<body>
    <div id="allMusic" ng-controller="musicItems">
        <div id="albums">
            <ul>
                <li>
                    <div class="title">Over The Mountains</div>
                    <ul>
                        <li>Over the mountains</li>
                        <li>!C3</li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</body>

1 Answer 1

2

Inner ngRepeat should be track in album.tracks (you have albums):

<li ng-repeat="track in album.tracks">{{ track.name}}</li>
<!-- extra "s" was here -----^ -->
Sign up to request clarification or add additional context in comments.

1 Comment

Oh wow now I feel stupid. Thanks for the help, didn't realize I could reference from the earlier ng-repeat. That's a neat trick.

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.