Home > Software design >  I am using subscribe method but getting an error in angular
I am using subscribe method but getting an error in angular

Time:11-27

I am new to angular. I am using old subscribe method but getting an error

    PosttoServer(){
    var cusdto:any = {};
    cusdto.CustomerCode = this.CustomerModel.CustomerCode;
    cusdto.CustomerName = this.CustomerModel.CustomerName;
    cusdto.CustomerAmount = this.CustomerModel.CustomerAmount;

    this.http.post("http://localhost:3000/posts",
    cusdto).subscribe(this.Success, this.Error);
  }

  Error(res){
    console.debug(res.json());
  }

  Success(res){
    this.CustomerModels = res.json();
  }

Error:

CustomerApp.CustomerComponent.ts:26 ERROR TypeError: res.json is not a function
    at Object.Error [as error] (CustomerApp.CustomerComponent.ts:31:23)
    at ConsumerObserver.error (Subscriber.js:102:33)

any suggestion how to use subscribe method.Thank you

CodePudding user response:

You don't need to add .json() It should work

  • Related