問題原本是想正確地設置在URL中的參數,但是,這篇文章解決了這個問題:How can I set a query parameter in AngularJS without doing a route?位置URL參數誤讀
然後一個新的問題又出現了。當設置在控制器中的網址,
$scope.view = function(itemtmpl) {
// change path and add parameter 'id' to the url
$location.path('/itemtemplates/view/').search('id', itemtmpl.itemdefnid);
// also tried with $routeProvider
$location.url('/itemtemplates/view/' + itemtmpl.itemdefnid);
};
商品的ID被解釋爲獨立的參數,而不是一個號碼(URL將被用來製造工場的REST調用,所以它必須是一個參數)。
這是首要的問題。
我覺得有我的$ location使用量的問題,所以我去了AngularJS文檔:https://docs.angularjs.org/api/ng/service/ $位置
仍然沒有運氣。
$ routeParams變量打印輸出表示相應地設置參數。
我可能需要澄清的另一個想法是,爲什麼我的網頁的配置將只承認時,它只是添加到末尾view/1000
,而不是如果它是一個參數view/?1000
的$ location.url,仍然它是否有一個ID將不會進行view/?id=1000
.config(function($routeProvider) {
$routeProvider.when('/itemtemplates/view/:id', {
templateUrl: 'itemtemplates/add/main.tpl.html',
controller: 'ViewCtrl'
});
})
我能錯過什麼?提前致謝。