我搜索了stackoverflow以获得一个简单的答案。是。我相信我错过了一些简单的事情。这一切都在学习过程中。谢谢参观。
更新。我现在能够导航到moreinfo.html视图,但我没有绑定数据。
航向 =======! Before modifications. index.html launches but 'View More Info' Links do Not work
航向 =======! After modifications. 'View More Info' links work but No Bound Data
航向 =======! moreinfo.html navigates fine to the view but again No Bound Data
stats.html
//Main Point of Entry.
<h2>Soccer</h2>
Filter: <input type="text" ng-model="playersFilter.name" />
<br /><br />
<ul>
<li>Sort By Category</li>
</ul>
<table>
<tr>
<th ng-click="doSort('Attempts')">Attempts</th>
<th ng-click="doSort('Goals')">Goals</th>
<th ng-click="doSort('Assists')">Assists</th>
<th ng-click="doSort('Fouls')">Fouls</th>
<th ng-click="doSort('Date')">Date</th>
<th ng-click="doSort('average')">Average</th>
</tr>
<tr ng-repeat="player in players | filter:playersFilter | orderBy:sortBy:reverse">
<td>{{ player.Goals }}</td>
<td>{{ player.Attempts }}</td>
<td>{{ player.Assists }}</td>
<td>{{ player.Fouls }}</td>
<td>{{ player.date | date }}</td>
<td>{{player.Goals / player.Attempts | number:2}}</td>
<td><a href ="#/moreinfo/{{ player.id }}"> View More Info</a></td>
</tr>
</table>
<br />
<span>Total Games: {{ players.length }}</span>
这是我点击链接时要导航到的页面&#39;查看更多信息&#39;来自stat.html页面。但没有任何反应,Chrome开发工具的控制台或网络选项卡中没有任何错误提示。
moreinfo.html
<h2>More Information</h2>
<table>
<tr>
<th>TeamImage </th>
<th>oppImage </th>
</tr>
<!--<tr ng-repeat ="player in players">-->
<td>{{player.Image}}</td>
<td>{{player.teamImage}}</td>
</tr>
</table>
我已经嵌入了json。
statsController.js
function() {
var StatsController = function ($scope) {
$scope.doSort = function(propName) {
$scope.sortBy = propName;
$scope.reverse = !$scope.reverse;
};
$scope.getAverage = function(){
var average = 0;
for(var i = 0; i < $scope.player.Goals.length; i++){
var a = $scope.player.Goals[i];
average += (player.Attempts / player.Goals);
}
return average;
}
$scope.players = [
{
id:1,
games: [
{
"Goals": 1,
"Attempts": 6,
"Image": "http://www.soccer1.png",
"opp": "USA",
"Assists": 0,
"team": "ECU",
"Fouls": 1,
"teamImage": "http://www.soccerTeam1.png",
"date": "2014-03-31"
},
{
"Goals": 0,
"Attempts": 3,
"Image": "http://www.soccer2.png",
"opp": "CHI",
"Assists": 1,
"team": "KAZ",
"Fouls": 1,
"teamImage": "http://www.soccerTeam2.png",
"date": "2014-04-02"
}
]
},
{
id:2,
games: [
{
"Goals": 2,
"Attempts": 2,
"Image": "http://www.soccer22.png",
"opp": "USA",
"Assists": 0,
"team": "ECU",
"Fouls": 1,
"teamImage": "http://www.soccerTeam22.png",
"date": "2014-03-31"
},
{
"Goals": 3,
"Attempts": 3,
"Image": "http://www.soccer33.png",
"opp": "CHI",
"Assists": 1,
"team": "KAZ",
"Fouls": 1,
"teamImage": "http://www.soccerTeam33.png",
"date": "2014-04-02"
}
]
}
];
};
StatsController.$inject = ['$scope'];
angular.module('sportsApp')
.controller('StatsController', StatsController);
}());
我在下面嵌入了json。这是很多冗余的代码。理想情况下,我希望将所有json放在一个单独的文件中并使用工厂,但我正在逐步完成此操作。
moreinfoController.js
(function() {
var MoreInfoController = function ($scope, $routeParams) {
// get to the route and the playerId
var playerId = $routeParams.playerId;
$scope.games = null;
function init() {
for (var i= 0, len=$scope.players.length; i<len; i++){
if($scope.players[i].id === parseInt(playerId)) {
$scope.games = $scope.players[i].games;
break;
}
}
}
// init();
$scope.players = [
{
id:1,
games: [
{
"Goals": 1,
"Attempts": 6,
"Image": "http://www.soccer1.png",
"opp": "USA",
"Assists": 0,
"team": "ECU",
"Fouls": 1,
"teamImage": "http://www.soccerTeam1.png",
"date": "2014-03-31"
},
{
"Goals": 0,
"Attempts": 3,
"Image": "http://www.soccer2.png",
"opp": "CHI",
"Assists": 1,
"team": "KAZ",
"Fouls": 1,
"teamImage": "http://www.soccerTeam2.png",
"date": "2014-04-02"
}
]
},
{
id:2,
games: [
{
"Goals": 2,
"Attempts": 2,
"Image": "http://www.soccer22.png",
"opp": "USA",
"Assists": 0,
"team": "ECU",
"Fouls": 1,
"teamImage": "http://www.soccerTeam22.png",
"date": "2014-03-31"
},
{
"Goals": 3,
"Attempts": 3,
"Image": "http://www.soccer33.png",
"opp": "CHI",
"Assists": 1,
"team": "KAZ",
"Fouls": 1,
"teamImage": "http://www.soccerTeam33.png",
"date": "2014-04-02"
}
]
}
];
init();
};
MoreInfoController.$inject = ['$scope','$routeParams'];
angular.module('sportsApp')
.controller('MoreInfoController', MoreInfoController);
}());
答案 0 :(得分:0)
您的链接说
<td><a href ="#/moreinfo{{ player.id}}"> View More Info</a></td>
但我在json中看不到播放器的任何id属性。
这似乎是一个问题。
此外,您的href中的moreinfo似乎也缺少/。