在Angular 8中,可以使用ActivatedRoute服务来获取和处理查询参数。以下是一个解决方法示例:
import { ActivatedRoute, Router } from '@angular/router';
constructor(private route: ActivatedRoute, private router: Router) {}
ngOnInit() {
this.route.queryParams.subscribe(params => {
// 处理查询参数
console.log(params['param1']);
console.log(params['param2']);
});
}
updateQueryParams() {
const queryParams = { param1: 'value1', param2: 'value2' };
this.router.navigate([], { queryParams });
}
在上面的示例中,updateQueryParams方法会将param1和param2设置为新的查询参数值,并导航到带有新查询参数的URL。