AngularJS - 测试字符串是否与路由匹配

标签 angularjs

当给出以下路线时,是否有 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/

相关文章:

javascript - 如何在javascript中显示小数点后两位数

javascript - angularjs 分数计数器不工作

javascript - AngularJS 变量未在 html 中显示

javascript - 如何动态地将新数组添加到现有数组

javascript - 动态 NG- Controller 名称

javascript - ng-repeat 中的 $scope.variable

javascript - 访问 AngularJS 指令中的 attrs

javascript - Angularjs watch 未触发

javascript - 过滤 ng-repeat 以从对象属性创建逗号分隔的数组值列表

javascript - 使用带有 getDay() 方法的 switch 语句?