0
我是Angular 2的新手。我試圖從API的響應後呈現模板,但我面臨的問題,如模板呈現後的API調用響應。Angular 2同步API調用
我的代碼片段的部分是:
ngOnInit() {
let productId = this.route.snapshot.params['id'];
this.CommonService.fetchData("http://192.168.1.107:9000/api/test/user/userId.json?id=" + productId).subscribe(
(data) => {
this.productData = data[0];
console.log(this.productData);
}
)
this.productAdd = this._formBuild.group({
firstName: [this.productData["firstName"]],
shortName: [this.productData["shortname"]],
})
}
fetchData(url){
return this.http.get(url).map(
(res) => res.json()
)
}
誰能幫助我?
您能爲我們提供了錯誤? –
'this.productAdd'是數組對象,我爲什麼要將它分配給FromBuild組? –
它是FormGroup的一個對象productAdd:FormGroup; –