最初的问题是试图正确设置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/$location
还是没有运气。
$routeParams变量输出表明参数是相应设置的。
另一个我可能需要澄清的想法是,为什么我的页面的配置只在$location.url被附加到结束view/1000时才会识别,而不是如果它是参数view/?1000,如果它有id view/?id=1000,它仍然不会继续运行。
.config(function($routeProvider) {
$routeProvider.when('/itemtemplates/view/:id', {
templateUrl: 'itemtemplates/add/main.tpl.html',
controller: 'ViewCtrl'
});
})我错过了什么?提前谢谢。
发布于 2014-10-09 19:56:02
在我试图访问的URL的控制器中,工厂调用是不正确的。我必须在REST调用中指定要实现的参数,否则,参数将被松散地解释。在我的例子中,作为一个char数组。
曾经..。
$scope.itemtmpl = item.query($routeParams.id);应该是..。
$scope.itemtmpl = item.query({id: $routeParams.id});这解决了问题的前半部分。当使用.search()设置参数时,我仍然试图弄清楚如何使用url。
https://stackoverflow.com/questions/26286338
复制相似问题