我需要一些帮助来从Angular2组件中的index.html访问查询字符串。我已经关注此链接,但它对我不起作用 link
我的index.html
<!doctype html>
<html>
<head>
<base href="/">
<!-- css importd -->
</head>
<body>
<app-root>Loading .. </app-root>
</body>
</html>
app.component.ts
...
public constructor(private activatedRoute:ActivateRoute) {}
ngOnInit() {
this.activateRoute.queryParams.subscribe((params:Params) => {
console.log(params['code']);
});
}
答案 0 :(得分:1)
试试这个:
constructor(private route: ActivatedRoute) { }
ngOnInit() {
// get param
let paramcode = this.route.snapshot.queryParams["code"];
}
答案 1 :(得分:0)
试试这个: -
this.activateRoute.queryParams.subscribe(queryParams =>
console.log(queryParams['code']);
);
添加你的html代码: -
<router-outlet></router-outlet>