Angular 使用特定格式检查 URL
Angular check URL with specific format
我想检查我的 URL 是否具有 特定的 格式。
我有这个 URL
www.example.com?rt=12365
我想检查收入 URL 是否具有以下格式
?rt= number
然后做点什么。
我像下面的代码一样使用路由器:
const queryParams = router.url
但我不知道如何检查它。我是 typescript 的新手 angular,请帮助我
试试这个
constructor(private route: ActivatedRoute) {
}
if (this.route.snapshot.queryParams['rt']) {
if ( !isNaN(this.route.snapshot.queryParams['rt']) && angular.isNumber(this.route.snapshot.queryParams['rt']))
{
}
}
希望对你有用
您可以使用queryParams
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.route.queryParams.subscribe(params => {
console.log(params.rt);
if(!isNaN(params.rt)){
console.log("URL Match");
}else{
console.log("URL does not Match");
}
});
}
我想检查我的 URL 是否具有 特定的 格式。 我有这个 URL
www.example.com?rt=12365
我想检查收入 URL 是否具有以下格式
?rt= number
然后做点什么。 我像下面的代码一样使用路由器:
const queryParams = router.url
但我不知道如何检查它。我是 typescript 的新手 angular,请帮助我
试试这个
constructor(private route: ActivatedRoute) {
}
if (this.route.snapshot.queryParams['rt']) {
if ( !isNaN(this.route.snapshot.queryParams['rt']) && angular.isNumber(this.route.snapshot.queryParams['rt']))
{
}
}
希望对你有用
您可以使用queryParams
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.route.queryParams.subscribe(params => {
console.log(params.rt);
if(!isNaN(params.rt)){
console.log("URL Match");
}else{
console.log("URL does not Match");
}
});
}