[英]Angular4 @Input() to pass value from parent component to child component
[英]how to pass a response to parent component from service provider component of angular4 (ionic3), i got undefined value?
在父組件中,我獲得了數據的不確定值。 這是我的代碼。
parentComponent.ts
testMethod(){
console.log('t', this.answer.postRequest(this.quetion).subscribe(data => {
console.log('d',data);
})); //here i got undefined value to data
}
serviceProvider.ts
postRequest(ques:string):Observable<any>{
let header = new HttpHeaders({
'Content-Type' : 'application/json',"Accept":'application/json'
});
console.log(ques)
return this.http.post(
"http://localhost:8080/hello",
{'q': ques},
{headers: header}
).map(data => {
console.log(data);
}, // this work fine and value is assigned to data as expected
error => {(error);// Error getting the data});
}
這樣使用
返回this.http.post(“ http:// localhost:8080 / hello ”,{'q':ques},{headers:header}).map(data => {console.log(data);})。 map((resp:Response)=> {return resp;});
這會有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.