AngularJS 1.0.7 routeParams解析

前端之家收集整理的这篇文章主要介绍了AngularJS 1.0.7 routeParams解析前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的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

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

解决方法

升级到角度1.2以执行此操作.

处理角度的标准方法是通过ngRoute和正则表达式(如herehere’s a plunker所示),但角度1.0.8不允许在路径模式中使用正则表达式(see here,ctrl f用于switchRouteMatcher) ).

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

猜你在找的Angularjs相关文章