我試圖通過顯示在index.html中的引導表中的songInfo.js和songInfo.html指令顯示存儲在MainController中的歌曲的信息。現在只有表頭顯示。任何幫助將不勝感激!如何使用Angularjs在引導表中顯示信息
的index.html:
<body ng-app="Hypalytics">
<div class="main" ng-controller="MainController"></div>
<div class="container">
<h2 class="table">Hover Rows</h2>
<table class="table table-hover">
<thead>
<tr>
<th>Rank</th>
<th>Song</th>
<th>Artist</th>
<th>Velocity</th>
<th>Days on Chart</th>
<th>Label</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="song in songs">
<td><song-info info="song"></song-info></td>
</tr>
</tbody>
</table>
</div>
MainController:
app.controller('MainController', ['$scope', function($scope) {
$scope.songs = [
{
title: 'Trap Queen',
artist: 'Fetty Wap',
label: 'Warner Music',
velocity: 3,
days: 5,
rank: 1,
},
{
title: 'Sorry',
artist: 'Justin Beiber',
label: 'Warner Music',
velocity: 17,
days: 4,
rank: 2,
},
{
title: 'Reaper',
artist: 'Sia',
label: 'Ultra Records',
velocity: 56,
days: 7,
rank: 3,
}
];
}]);
songInfo.html:
<td class="rank">{{ song.rank }}</td>
<td class="title">{{ song.title }}</td>
<td class="artist">{{ song.artist }}</td>
<td class="velocity">{{ song.velocity }}</td>
<td class="days">{{ song.days }}</td>
<td class="label">{{ song.label }}</td>
songInfo.js
app.directive('songInfo', function() {
return {
restrict: 'E',
scope: {
info: '='
},
templateUrl: 'js/directives/songInfo.html'
};
});
個
app.js
var app = angular.module('Hypalytics', []);
爲什麼要使用songInfo指令?你可以把它在這裏呈現在表格內 –