如果给出以下路线,是否有角度的方式
.when('/customer/:customerId',{ templateUrl: 'views/summary.tpl.html',controller: 'SummaryController' })
能够测试一个字符串是否匹配该路由?
例如,使用字符串
'/customer/3'
解决方法
您可以遍历所有已定义的路由并检查是否存在匹配:
angular.forEach($route.routes,function(route) { if(route.regexp.exec(myURL)){ match = true; } })
检查this fiddle.