Ng-repeat not rendering content

522 Views Asked by At

I'm writing a web app using Node.js+Express to serve (with HoganJs as a templating engine) and AngularJS on the frontend. I'm having problems with ng-repeat rendering the correct number of elements, but without any content in. I broke the ng-repeat down into a smaller example and it's still not rendering.

EDIT: There was a typo in the Plunkr, so I removed it. Here's a more expanded extract from my app.

Here's a section of my view: index.hjs

<div class="search-results" ng-controller="results">
    <ul class="tracks">
        <li class="track" ng-repeat="track in tracks">
                <ul class="meta">
                    <li>
                        <div class="name">
                            <span class="value">{{track.name}}</span>
                        </div>  
                    </li>
                    <li>
                        <div class="album">Album: 
                            <span class="value">{{track.album}}</span>
                        </div>  
                    </li>
                    <li>
                        <div class="artist">Artist:  
                            <span class="value">{{track.artist}}</span>
                        </div>  
                    </li>
                    <li>
                        <div class="length">Length:  
                            <span class="value">{{track.length}}</span>
                        </div>  
                    </li>
                </ul>   
            </li>
        </ul>
    </div>

The results controller: js/controllers/results.js

var results = function($scope, socket) {
    $scope.tracks = [
        {"uri":"spotify:track:1jdNcAD8Ir58RlsdGjJJdx","name":"Ho Hey","artist":"The Lumineers","album":"The Lumineers"},
        {"uri":"spotify:track:3uuGbRzMsDI5RiKWKOjqWL","name":"Hey Porsche","artist":"Nelly","album":"Hey Porsche"},
        {"uri":"spotify:track:5BSndweF91KDqyxANsZcQH","name":"Ho Hey","artist":"The Lumineers","album":"The Lumineers"},
        {"uri":"spotify:track:2UNc0duOP4cS7gqYFFkwxT","name":"Hey Girl","artist":"Billy Currington","album":"Hey Girl"},
        {"uri":"spotify:track:6fgbQt13JlpN59PytgTMsA","name":"Snow [Hey Oh]","artist":"Red Hot Chili Peppers","album":"Snow [Hey Oh]"}
    ];

    socket.on("results", function(tracks) {
        $scope.tracks = tracks;
        console.dir(JSON.stringify($scope.tracks));
    });

    $scope.add = function(uri) {
        socket.emit("add", uri);
    };
};

And finally my module: app.js

var app = angular.module("app", []);

var factories = {
    socket: socket
};
app.factory(factories);

var controllers = {
    actions: actions,
    search: search,
    results: results,
    queue: queue
};
app.controller(controllers);

For testing purposes, the tracks are hardcoded in when the app is run 5 lis are rendered but there no content has been templated inside of them.

3

There are 3 best solutions below

0
On BEST ANSWER

I've just realised what's happening here. Hogan.js is overwriting angular's templates when the page is rendered at the server.

0
On

Remove a ) here:

      ];
   });
    ^

Plnkr: http://plnkr.co/edit/e0URFt?p=preview

0
On

Just remove the extra bracket added to your script (line 19). Please look at the script here. http://plnkr.co/edit/sy2m0RuXRudGvjnmfC3Y?p=preview