无法加载资源:服务器以状态404(未找到)响应ERROR HttpErrorResponse

时间:2019-03-11 10:59:01

标签: angular

我目前正在开发Angular 7应用程序。当我尝试调用http发布时,当网络api返回成功消息时,它工作正常,当api返回错误消息时,我得到了错误。消息返回类似{Error = true,Message =“ invalid data”}

error massege image

service.ts

addCustomer(customer: Customer) {
        const body: Customer = {
           // do...
        };
        return this.http.post(this.apiurl + 'Products/Post', body);
    }

component.ts

 OnSubmit(form: NgForm) {
    this.apiservice.addCustomer(form.value).subscribe((data: any) => {

      if (data.Error === false) {
        this.resetForm(form);
        this.toastr.success(data.Message);
            } else {
        this.toastr.error(data.Message);`enter code here`
      }
    });
  }

0 个答案:

没有答案