我有这个控制器:
(function(){
'use strict';
angular.module('eliteApp').controller('TeamDetailCtrl',['$stateParams',$ionicPopup,'eliteApi',TeamDetailCtrl]);
function TeamDetailCtrl($stateParams ,$ionicPopup , eliteApi){
var vm = this;
//console.log('$stateParams',$stateParams);
//$stateParams are using to access to parameters in the link
vm.teamId = Number($stateParams.id);
eliteApi.getLeagueData().then(function(data){
var team = _.chain(data.teams)
.flatten("divisionTeams")
.find({"id":vm.teamId})
.value();
vm.teamName = team.name;
vm.games = _.chain(data.games)
.filter(isTeamInGame)
.map(function(item){
var isTeam1 = (item.team1Id === vm.teamId ? true : false);
var opponentName = isTeam1 ? item.team2 : item.team1;
var scoreDisplay = getScoreDisplay(isTeam1 , item.team1ScoreDisplay,item2.team2ScoreDisplay);
return{
gamed : item.id,
opponent: opponentName,
time: item.time,
location: item.location,
locationUrl: item.location.locationUrl,
scoreDisplay: item.scoreDisplay,
homeAway: (isTeam1 ? "vs." : "at")
};
})
.value();
vm.teamStanding = _.chain(data.standings)
.flatted("divisionStandings")
.find({"teamId" : vm.teamId})
.value();
})
vm.following = false;
vm.toggleFollow = function(){
if(vm.following){
var confirmPopup = $ionicPopup.confirm({
title: 'Unfollow?',
template: 'Are you sure you want to unfollow?'
});
confirmPopup.then(function(res){
if(res){
vm.following = !vm.following;
}
})
}
else{
vm.following = !vm.following;
}
};
function isTeamInGame(item){
return item.item1Id === vm.teamId || item.team2Id === vm.teamId;
}
function getScoreDisplay (isTeam1 , team1Score , team2Score) {
if (team1Score && team2Score) {
var teamScore = (isTeam1 ? team1Score : team2Score);
var opponentScore = (isTeam1 ? team2Score : team1Score);
var winIndicator = teamScore > opponentScore ? "W: " : "L:";
return winIndicator + teamScore + "-" + opponentScore;
}
else
{
return"";
}
}
};
})
和team-detail.html文件:
<ion-view ng-controller="TeamDetailCtrl as vm" title="{{vm.teamName}}">
<ion-content class="has-header">
<div class="card">
<div class="item item-button-right">
<h2>Record: {{vm.teamStanding.wins}}--{{vm.teamStanding.losses}}</h2>
<button class="button button-positive icon-left"
ng-class="{'icon-checkmark-round': vm.following,'ion-plus-round button-outline':!vm.following}" ng-click="vm.toggleFollow()">
{{vm.following ? "Following" : "Not Following"}}
</button>
</div>
</div>
<div class="list">
<a class="item item-icon-right" ng-repeat="game in vm.games" ui-sref=
"app.game({id: game.gameId})">
{{game.opponent}} {{game.scoreDisplay}}
<div class="row">
<div class="col-20 col-center">
<p>{{game.time | date:'m/d/yy'}}</p>
<p>{{game.time | date:'shortTime'}}</p>
</div>
<div class="col">
<h3>{{game.homeAway}} {{game.opponent}}</h3>
<p>{{game.location}}</p>
</div>
<div class="col-20 col-center">
<h4 class="positive">{{game.scoreDisplay}}</h4>
</div>
</div>
<i class="icon ion-chevron-right icon-accessory"></i>
</a>
</div>
</ion-content>
</ion-view>
在此HTML页面中,当我点击任何链接时,它会将我重定向到具有正确ID的team-detail.html页面:
<ion-view title="teams" ng-controller="TeamsCtrl as vm">
<ion-content class="has-header">
<div class="list">
<div ng-repeat="division in vm.teams">
<div class="item item-divider item-energized">{{division.divisionName}}</div>
<a class="item item-icon-right" ng-repeat="team in division.divisionTeams"
href="#/app/teams/{{team.id}}">{{team.name}}
<i class="icon ion-chevron-right icon-accessory"></i>
</a>
</div>
</div>
</ion-content>
</ion-view>
我搜索了很多但没有解决方案。 我没有忘记将链接添加到index.html页面。
路由文件app.js:
angular.module("eliteApp" , ["ionic","angular-cache"])
.run(function($ionicPlatform, CacheFactory) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
CacheFactory("leagueDataCache",{storageMode:"localStorage", maxAge:50000 , deleteOnExpire:"aggressive"});
CacheFactory("leaguesCache",{storageMode:"localStorage", maxAge:50000 , deleteOnExpire:"aggressive"});
CacheFactory("myTeamsCache",{storageMode:"localStorage"});
CacheFactory("staticCache",{storageMode:"localStorage"});
});
})
.config(function($stateProvider , $urlRouterProvider){
$stateProvider
.state('home' ,{
abstract: true,
url: "/home",
templateUrl:"app/home/home.html"
})
.state('home.leagues',{
url: "/leagues",
views:{
"tab-leagues":{
templateUrl: "app/home/leagues.html"
}
}
})
.state('home.myteams',{
url: "/myteams",
views:{
"tab-myteams":{
templateUrl: "app/home/myteams.html"
}
}
})
.state('app', {
abstract:true,
url: '/app',
templateUrl:"app/layout/menu-layout.html"
})
.state('app.teams',{
url: "/teams",
views:{
"mainContent":{
templateUrl: "app/team/teams.html"
}
}
})
.state('app.teams-details',{
url: "/teams/:id",
views:{
"mainContent":{
templateUrl: "app/team/team-detail.html"
}
}
})
.state('app.game',{
url: "/game/:id",
views:{
"mainContent":{
templateUrl: "app/game/game.html"
}
}
})
.state('app.standings',{
url: "/standings",
views:{
"mainContent":{
templateUrl: "app/standings/standings.html"
}
}
})
.state('app.locations',{
url: "/locations",
views:{
"mainContent":{
templateUrl: "app/locations/locations.html"
}
}
})
.state('app.rules',{
url: "/rules",
views:{
"mainContent":{
templateUrl: "app/rules/rules.html"
}
}
})
$urlRouterProvider.otherwise('/app/teams');
});