本文介绍了angularjs路线可以有可选的参数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以设置可选的PARAMS(相同的模板和控制器的路线,但如果他们不存在某些PARAMS应该被忽略?
Can I set a route with optional params (same template and controller, but some params should be ignored if they don't exist?
因此,而不是写以下两条规则中,只有一个?
So instead of writing the following two rules, have only one?
module.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/users/', {templateUrl: 'template.tpl.html', controller: myCtrl}). when('/users/:userId', {templateUrl: 'template.tpl.html', controller: myCtrl}) }]);像这样的东西([此参数是可选])
Something like this ([this param is optional])
when('/users[/:userId]', {templateUrl: 'template.tpl.html', controller: myCtrl}) //note: this previous doesn't work我找不到自己的文档中的任何东西。
I couldn't find anything in their documentation.
推荐答案它看起来像角现在有这种支持。
It looks like Angular has support for this now.
从最新的(V1.2.0)文档的 $ routeProvider.when(道路,路线) :
From the latest (v1.2.0) docs for $routeProvider.when(path, route):
路径可以包含一个问号可选命名组(:名称)
path can contain optional named groups with a question mark (:name?)
更多推荐
angularjs路线可以有可选的参数值?
发布评论