好的,所以我有一個Angular模塊按照頁面加載的意圖工作 - 像site.com#/ catalog/1234這樣的網址。 $資源獲取重新加載視圖的數據,但不是在hashchange上。
我需要添加什麼來獲得hashchange來觸發新的獲取?
angular.module('Catalog', ['ngResource'])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/catalog/:categoryid', {
controller: 'CatalogListCtrl',
templateUrl:'/layout/responsive/html/catalogListView.html'
})
.otherwise({ redirectTo:'/' });
})
.factory('CatalogList', function($resource, $routeParams) {
var list = $resource('/test/products.json?query=:categoryid', { categoryid : $routeParams.categoryid }, {
query: { method: 'GET', isArray : true }
});
return list;
})
.controller('CatalogListCtrl', function ($scope, CatalogList) {
$scope.products = CatalogList.query();
});
你是什麼意思hashchange? – Narretz
你不能真的注入$ routeParams到服務聲明中,我不這麼認爲。只有控制器。 –
@blesh是正確的。但是,您可以注入$ route並通過$ route.current訪問當前參數。 – qualidafial