I want to refresh the page from the function in angular

38 views Asked by At

i am new to the angular i tried to make this work, here the "confirmDoctor" function is making some changes through the api, now i want the the way to automatically refresh the page of some angular change detection, so that it will call the getInfo method again give me the updated value. right now i have to manually refresh my browser to see the change.

 async confirmDoctor(selectedDoctor:string,pid:string){
    console.log(selectedDoctor);
    await this.assign.AssignDoctor(selectedDoctor,pid).subscribe(
      (response)=>{
        console.log(response);
        })  
  }

  ngOnInit(){

    this.getinfo.getInfo('patient').subscribe((response)=>
    {
      this.data = response;
      console.log(this.data);
    })
    this.doc$ = this.getinfo.getInfo('doctor');
  }
}

as i am new to the angular i dont really know what i need, i tried some change detection methods but i couldn't do it, what worked is calling ngOnInit() again inside the function, but i dont think its the right solution.

2

There are 2 answers

0
Gaurav Soni On

put the "this.getinfo.getInfo(..." in a separate private method for example:

    //type param here is your info entity i.e: patient, doctor etc.
    private getInfo(type: string){   
      this.getinfo.getInfo('patient').subscribe((response)=>
      {
        this.data = response;
        console.log(this.data);
      });
   }

call this in ngOnInit(), and similarly inside the subscription block of confirmDoctor()

0
Mudassar Mustafai On

You want to get the updated value of the "getInfo('patient')" method, for this, You can make another reusable function with the "getInfo" method implementation and use that function in ngOnInit, and in the response "AssignDoctor" method then you can get the updated value.