AngularJS 1.0.7 routeParams 解析

标签 angularjs

我的 app.js 中有这个规则:

$routeProvider.when('/:language/rental-:type-:departure', {templateUrl: 'partials/rental.html', controller: 'itemCtrl'});

当用户输入如下网址时:/en/rental-houses-santa-cruz-tenerife
然后:
var type = $routeParams.type;     # houses-santa-cruz                                  
var departure = $routeParams.departure; # tenerife

当我的预期结果是:
type = houses
departure = santa-cruz-tenerife

有没有办法实现这一目标?

最佳答案

升级到 angular 1.2 来做到这一点。

在 angular 中处理这个的标准方法是通过 ngRoute 和正则表达式(如显示 herehere's a plunker ),但 angular 1.0.8 不允许您在路由模式中使用正则表达式( see here , ctrl+f 用于switchRouteMatcher)。

如果将您的版本升级到 1.2 是不可能的,您也可以 fork angular 1.0.8 并添加更新 switchRouteMatcher 方法。

关于AngularJS 1.0.7 routeParams 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33762920/

相关文章:

html - 如何根据需要制作一个ui-select字段?

javascript - 在 http 请愿后选择 angularjs 不更新标题

AngularJS- 对匿名 Controller 进行单元测试

AngularJS Google Oauth 400 错误 redirect_uri : Fragment not allowed 的参数值无效

javascript - AngularJS View 中的 SublimePlayer

javascript - 异步请求附加到 Angular 中的字符串

javascript - angularJS http GET参数在服务器上未定义

javascript - JSON 数组去重

angularjs - MEAN.js : Get number of users stored in MongoDB

javascript - 以 Angular 限制同时异步 $http get 请求