我一直在寻找为这种网址设置参数的方法,但我不能
http://localhost:9111/v1/companies/ {公司} /用户
{Company} 是参数
任何人都知道如何为此网址设置参数?
答案 0 :(得分:1)
您可以轻松使用template literals!
let company = 'google';
return this.http.get(`http://localhost:9111/v1/companies/${company}/users`);
答案 1 :(得分:1)
轻微更新
跳转到此部分可能会更快:https://angular.io/docs/ts/latest/guide/router.html#!#link-parameters-array
<强>原始强>
阅读角度文档的这一部分应该详细解释您尝试做的事情:https://angular.io/docs/ts/latest/guide/router.html#!#route-def-with-parameter
在路由模块中,您可以使用〜{ path: 'v1/companies/:companyId/users', component: TheComponent }