Home > Mobile >  Property 'subscribe' does not exist on type 'void'.ts(2339).Am getting this erro
Property 'subscribe' does not exist on type 'void'.ts(2339).Am getting this erro

Time:05-13

I am new in angular and am getting this error while implementing subscribe function after calling it from the service.This is component.ts file

 OnSubmit(){
      this.formModal.email=this.profileForm.value.email;
      this.formModal.name=this.profileForm.value.name;
      this.formModal.ph=this.profileForm.value.ph;
      this.formModal.stateValue=this.profileForm.value.stateValue;
     this.api.postValues(this.formModal).subscribe((data: any)=>{
       console.log(data)
     })
    }
    }
    //Services
    export class FormsService {
       baseurl='http://localhost:3000/posts:'
    
      constructor(private http:HttpClient,private formodal:FormModal) { }
    postValues(values:any){
    this.http.post(this.baseurl,values).pipe(map((res)=>{return res}))
    }
    }


           

CodePudding user response:

You're not returning anything in postValues, therefore it's a void function.

Do this instead:

return this.http.post(this.baseurl,values).pipe(map((res)=>{return res}));

  • Related