gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 02:20:43 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com