Javascript angularjs状态提供程序在url中使用id以外的其他值
我正在使用Javascript angularjs状态提供程序在url中使用id以外的其他值,javascript,angularjs,html,angularjs-routing,angularjs-controller,Javascript,Angularjs,Html,Angularjs Routing,Angularjs Controller,我正在使用$stateProvider为我的应用程序规划路线。我希望url是有意义的,这样我就可以得到新闻应用程序的日期、类别和标题,而不是url中的id 目前,我可以获得加载所需模板的状态 .state('viewArticle', { url: '/news/:articleId', templateUrl: 'view-article.html' }) 我得到http://www.example.com/#!/新闻/5517374f286f
$stateProvider
为我的应用程序规划路线。我希望url是有意义的,这样我就可以得到新闻应用程序的日期、类别和标题,而不是url中的id
目前,我可以获得加载所需模板的状态
.state('viewArticle', {
url: '/news/:articleId',
templateUrl: 'view-article.html'
})
我得到http://www.example.com/#!/新闻/5517374f286ff5ba79037568
我想获得与我的文章相同的视图,并显示urlhttp://www.example.com/#!/新闻/2015-04-04/天气/明天
当我在状态下硬编码url时,我可以实现这一点
.state('viewArticle', {
url: '/news/2015-04-04/weather/tomorrow',
templateUrl: 'view-article.html'
})
但我无法解决如何将多个参数从我的数据传递到url中。
这可能吗?如何才能最好地实现这一点
这是我提出的,但没有成功
//angular.module().config
.state('viewArticle', {
//url: '/news/:articleId',
//url: '/news/2015-04-04/weather/tomorrow',
url: '/news/:year/:category/:title',
templateUrl: 'view-article.html'
})
//view-article.html (this seems ok as it works when state hard coded)
go('/' + article.date + '/' + article.category + '/' + article.title
//controller
$scope.go = function(path) {
$location.path( path );
};
我认为您应该使用
角度ui路由器的$state.go()
,而不是$location.path
方法
$state.go('viewArticle',{year: article.date, category: article.category, title: article.title });
你的意思是go('/news/'+ar…
,对吗?@SergiuParaschiv yes你可能需要$scope.$apply()
在$location.path
@ak85之后它对你有帮助吗?