来自ActivatedRoute params的Angular 4原始字符串

时间:2018-04-04 21:21:58

标签: node.js angular express

我一直在寻找无法找到答案的地方。我在url示例中传递了一个字符串。 "本地主机:4200 /家庭/ ABCD%2BrAD4Og%3D%3D"当我订阅参数或使用快照时,我会得到像#34; ABCD + rAD4Og ==" 我如何得到确切传递的内容?谢谢

1 个答案:

答案 0 :(得分:1)

我找到了答案。如果你想获得传递的原始参数,你只需要使用" encodeURIComponent(uri)"

import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-example',
template: `<h1>raw URI example</h1>`,
styleUrls: ['./example.component.scss']
})
export class ExampleComponent implements OnInit {
constructor(private router: ActivatedRoute) {}
rawUri: string = null;
ngOnInit() {
this.router.params.subscribe(param => {
// the "id" part inside param[''] could be anything you defined in your route config file.
this.rawUri = encodeURIComponent(param['id']);
console.log('raw url param ', this.rawUri);
    }
  }

}
相关问题