2014-05-04 39 views
0

更新,我已经尝试添加$route.refresh到链接的ng-click到这些网页,但这也不起作用。有任何想法吗?内容没有在路由变化

下面是路由代码,这个工作正常,所有的路由都是通过链路完成的,只是<a>这个标签表示href的路由。

angular.module('magicApp', ['ngRoute']).config(['$routeProvider', function($routeProvider) { 
$routeProvider.when('/', { 
     templateUrl: 'pages/home.html' 
    }).when('/set', { 
     redirectTo: '/sets' 
    }).when('/set/:setID', { 
     controller: 'SetInformationController', 
     templateUrl: 'pages/set.html' 
    }).when('/card', { 
     redirectTo: '/cards' 
    }).when('/card/:cardID', { 
     controller: 'CardInformationController', 
     templateUrl: 'pages/card.html' 
    }).when('/sets', { 
     controller: 'SetListController', 
     templateUrl: 'pages/sets.html' 
    }).when('/cards', { 
     controller: 'CardListController', 
     templateUrl: 'pages/cards.html' 
    }).when('/search/:searchterm', { 
     controller: 'SearchController', 
     templateUrl: 'pages/search.html' 
    }).otherwise({ 
     redirectTo: '/' 
    }); 
}]); 

下面是对SetListController的代码,它使用routeParams抢从服务,其工作,当我去/set/1然后返回正确的信息,如果我再回去了正确的信息,然后去到/set/2它仍然显示来自第1组的信息,直到我刷新页面。

.controller('SetInformationController', function($scope, $routeParams, $route, SetInformationService, CardSetInformationService) { 
$scope.set = []; 
$scope.cards = []; 

function init() { 
    SetInformationService.async($routeParams.setID).then(function(d) { 
     $scope.set = d; 
    }); 
    CardSetInformationService.async($routeParams.setID).then(function(d) { 
     $scope.cards = d; 
    }) 
} 

init(); 
}) 

的HTML本身没有参考控制器,或类似的东西,只是在范围内,即setcards的对象。

+0

,请复制粘贴代码显示路线配置,以及用于更改路线的代码。 –

+0

我用它编辑了主帖。 –

+0

你没有路由控制器'/ set /:setID' – Sebastian

回答

0

我想通了!这个问题实际上并没有用它与我的服务路由,这里是以前的服务:

.factory('SetInformationService', function($http) { 
    var promise; 
    var SetInformationService = { 
    async: function(id) { 
     if (!promise) { 
      // $http returns a promise, which has a then function, which also returns a promise 
      promise = $http.get('http://api.mtgdb.info/sets/' + id).then(function (response) { 
      // The then function here is an opportunity to modify the response 
      console.log("Set Information"); 
      console.log(response); 
      // The return value gets picked up by the then in the controller. 
      return response.data; 
      }); 
     } 
     // Return the promise to the controller 
     return promise; 
    } 
    }; 
    return SetInformationService; 
}) 

它应该是:

.factory('SetInformationService', function($http) { 
    var promise; 
    var SetInformationService = { 
    async: function(id) { 
     // $http returns a promise, which has a then function, which also returns a promise 
     promise = $http.get('http://api.mtgdb.info/sets/' + id).then(function (response) { 
     // The then function here is an opportunity to modify the response 
     console.log("Set Information"); 
     console.log(response); 
     // The return value gets picked up by the then in the controller. 
     return response.data; 
     }); 
     // Return the promise to the controller 
     return promise; 
    } 
    }; 
    return SetInformationService; 
})