Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Property 'subscribe' does not exist on type 'void'.ts(2339).Am getting this error

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}))
    }
    }


           

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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}));

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading