Skip to content
Advertisement

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

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'
 }
}

Advertisement

Answer

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'
    }
}
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement