【发布时间】:2019-02-20 16:08:23
【问题描述】:
我有一个asp.net 后端服务。后端 api 在postman
但是从角度做同样的事情是行不通的。正文不会发送到服务器。我正在使用角度 7。
这是我的代码。
乳品服务
public addNewDairy(value) {
return this.http.post(this.apiUrl + "dairy", value)
.pipe(
map(success => success),
catchError(this.hes.handleError) // then handle the error
);
}
和组件
requestForRegistration(value) {
this.jqxLoader.open();
this.ds.addNewDairy(value).subscribe(res => {
this.jqxLoader.close();
this.message = "Requested for activation.";
this.notification.open();
}, error => {
console.log(error);
this.jqxLoader.close();
this.message = "Something went wrong please try again!";
this.notification.open();
});
}
【问题讨论】:
-
你调试过并确认你的值不是未定义的吗?
-
是的,先生。有价值呈现。它正在
addNewDairy方法中打印 -
"Http" 已弃用。你能改用 HttpClient 吗?
-
使用了相同的
HttpClient并从@angular/common/http导入
标签: angular typescript asp.net-web-api httpclient