angularjs路线可以有可选的参数值?

编程入门 行业动态 更新时间:2024-10-26 22:18:12
本文介绍了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路线可以有可选的参数值?

本文发布于:2023-07-14 22:15:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可选   路线   参数   angularjs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!