将字符串查询参数传递给angular

时间:2018-04-03 17:23:02

标签: javascript angular angular4-router

如何将字符串查询传递给angular4中的params 获取此URL http://localhost:3000/reviews?business_id=KNpcPGqDORDdvtekXd348w

2 个答案:

答案 0 :(得分:0)

你可以试试这个

import { ActivatedRoute, Router } from "@angular/router"
private router: Router, //the router variable should be added in the constructor

const route = "revews"
const params = {query: "superQuery"}
this.router.navigate([route, params])

答案 1 :(得分:0)

如果您想直接在html中执行此操作,请尝试以下操作:

<a [routerLink]="url" [queryParams]="param">link<\a>

其中,

url: string = '/reviews'; param: object = { business_id: 'KNpcPGqDORDdvtekXd348w' };