当给出以下路线时,是否有 Angular 的方法
.when('/customer/:customerId', {
templateUrl: 'views/summary.tpl.html',
controller: 'SummaryController'
})
能够测试字符串是否与该路由匹配?
例如与字符串
'/customer/3'
是否有 Angular 函数可以调用以确定路线是否与路线匹配?
最佳答案
您可以遍历所有定义的路由并检查是否存在匹配项:
angular.forEach($route.routes, function(route) {
if(route.regexp.exec(myURL)){
match = true;
}
})
查询 this fiddle .
关于AngularJS - 测试字符串是否与路由匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20700305/