我需要一些幫助來訪問Angular2組件中index.html的查詢字符串。我按照這個鏈接,但它並沒有爲我 link將查詢字符串從index.html傳遞到Angular2組件
我的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']);
});
}
而且我調用URL http://localhost:8080/?code=test
我沒有跟着你..我怎麼可以設置模板查詢參數..?他們即將到來的網址。謝謝 –
對不起,我想看看你的HTML代碼通過queryparams –
更新了HTML代碼。其非常簡單的文件 –