我的 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 和正则表达式(如显示 here 和 here'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/