简体   繁体   English

如何在 json url angular 中插入参数?

[英]HOw to insert parameter inside json url angular?

I want to add a parameter in my url but I don't know how to do it我想在我的 url 中添加一个参数,但我不知道该怎么做

ts.file文件

route(name:string) {
 this.router.navigate(['/homepage', (name)]);
 console.log('name);
}

service服务

private url1 = './assets/json/one/first.json'

constructor(private http: HttpCient) {}

get(): Observable<Itoto[]> {
return this.http.get<Itoto[]>(this.url1);
}

getRoute() {
 this.activatedRoute.paramMap.subscribe(params => {
  this.result = params.get('toto'); // i need add toto inside the url like './assets/json/toto/first.json'
 }
}

service服务

private url1 = './assets/json/one/first.json'

getRoute() {
    this.activatedRoute.paramMap.subscribe(params => {
    this.result = this.url1.replace("/one/", "/toto/"); // i need add toto inside the url like './assets/json/toto/first.json'
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM