I'm new in AngularJS. I'm trying to create the dynamic table in a view:
<table class="table">
<thead>
<tr>
<td>Name</td>
<td>Genre</td>
<td>Duration</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="album in getAlbumsInfo(artists)">
<td>{{ album.name }}</td>
<td>{{ album.genre }}</td>
<td>{{ album.duration }}</td>
</tr>
</tbody>
</table>
Here is my controller (artists
received from the backend):
$scope.getAlbumsInfo = function (artists) {
var albumsData = [];
artists.forEach(function (artist) {
var albumItemMap = new Map();
albumItemMap.set("name", artist.name);
albumItemMap.set("genre", artist.genre);
albumItemMap.set("duration", artist.geduration);
albumsData.push(albumItemMap);
});
return albumsData;
};
But it doesn't show any data in the table. Just simple table.
I've checked if I use the hard-code data from the $scope
something like:
$scope.albums = [
{ name: 'Cali Roll', genre: 'Pop', duration: 45 },
{ name: 'Philly', genre: 'Rock', duration: 50 },
{ name: 'Rainbow', genre: 'Relax', duration: 55 }
];
and (part of view):
<tr ng-repeat="album in albums">
It works fine. But, in the case with the function getAlbumsInfo
it doesn't work. What am I doing wrong?
UPD: I need only one function, it's mandatory condition.