POST请求在angular CLI版本7中不起作用
当发送POST请求在angular CLI版本7中不起作用,angular,rxjs,Angular,Rxjs,当发送http请求时,我遵循了文档并创建了以下服务 我尝试过使用angular version 5语法,但没有成功 createCartProduct(cartpr : CartProduct): Observable<CartProduct> { console.log("createCartProduct",cartpr); return this.http.post<CartProduct>(this.apiURL+'CartProduct', ca
http
请求时,我遵循了文档并创建了以下服务
我尝试过使用angular version 5语法,但没有成功
createCartProduct(cartpr : CartProduct): Observable<CartProduct> {
console.log("createCartProduct",cartpr);
return this.http.post<CartProduct>(this.apiURL+'CartProduct', cartpr, this.httpOptions)
.pipe(
retry(1),
catchError(this.handleError)
);
}
createCartProduct(cartpr:CartProduct):可观察{
console.log(“createCartProduct”,cartpr);
返回this.http.post(this.apirl+'CartProduct',cartpr,this.httpOptions)
.烟斗(
重试(1),
catchError(this.handleError)
);
}
这是我的全部
我已经将其添加到我的应用程序模块中的提供者
console.log
按预期工作,但post请求似乎不工作
我是angular的新手,如有任何帮助,我将不胜感激。您必须订阅
http.post
才能获得任何回复。例如:
this.createCartProduct().subscribe((data)=> console.log(data));
在您的场景中,我会这样做:
this.http.post<CartProduct>(this.apiURL+'CartProduct', cartpr, this.httpOptions)
.pipe(
retry(1),
catchError(this.handleError)
).pipe(take(1)).subscribe();
this.http.post(this.apirl+'CartProduct',cartpr,this.httpOptions)
.烟斗(
重试(1),
catchError(this.handleError)
).pipe(take(1)).subscribe();
来自angular docs:
HttpClient方法在您调用之前不会开始其HTTP请求
订阅()方法返回的可观察对象。这是真的
对于所有HttpClient方法
我感觉你忘了订阅你的可观察到的。在您订阅Observable之前,不会触发呼叫。请解释一下如何进行?或者任何在线材料?您可以看看RxJs的文档: