Angular4获取具有多个参数的查询字符串

时间:2018-05-25 10:04:39

标签: angular routing

我刚遇到一个非常奇怪的问题。 我有这段代码:

ngOnInit() {
  this._activatedRoute.queryParams.subscribe((params: Params) => {
    // Only update the elq if it changes (remember: changing a parameter causes the page to refresh)
    var elq = params['elqid'];
    console.log(params);
    console.log(elq);
    if (elq) {
      this._resultsService.elq = elq;
    }
  });
}

如果我这样做:

  

http://localhost:4200/steps/one?elqid=RStesting123

我确实得到了2个控制台日志输出:

{
    elqid: "RSTesting123"
}

如果我这样做:

  

http://localhost:4200/steps/one?cid=em-elq-33781&elqid=RStesting123

它也可以正常工作。 但是,如果我这样做(而不是&我正在使用&):

  

http://localhost:4200/steps/one?cid=em-elq-33781&elqid=RStesting123

我得到了这个输出:

{
    amp;elqid: "RSTesting123"
}

这不是我的预期。 我如何才能使用&并正确阅读?

1 个答案:

答案 0 :(得分:0)

根据您的意见,您写了

http://localhost:4200/steps/one?cid=em-elq-33781&elqid=RStesting123

它不会起作用,因为&被称为HTML Entity,它只能在HTML中读取,而不能在URL中读取。

相关问题