【发布时间】:2018-05-07 08:31:34
【问题描述】:
如果 URL 如下所示,我可以获取查询参数:
http://localhost:4200/member/0?members=1&facility=1&field=name&criteria=contains&string=black
当浏览器对上述网址中的$、= 和? 进行编码时,我无法检索查询参数,
编码后的 URL 如下所示:
下面是一段代码,我试图检索查询参数(在 URL 未编码时工作正常,但在浏览器对 URL 编码时失败)。
this._activatedRoute.snapshot.queryParams;
this._activatedRoute.queryParams.subscribe(value=> {
console.log('here');
console.log(value);
});
我使用的是Angular版本2.3.1,路由器版本是3.3.1
【问题讨论】:
-
constructor( private route: ActivatedRoute, private router: Router) {} ngOnInit() { this.sub = this.route .queryParams .subscribe(params => { // Defaults to 0 if no query param provided. this.page = +params['page'] || 0; }); } -
@KishanOza,它不起作用。获取默认值 0