Home > Software design >  Need to redirect to another page after submit in Angular
Need to redirect to another page after submit in Angular

Time:12-08

I have a page called Update Profile. When Submit button is pressed, currently it is reloading the page only. I need that it could redirect to dashboard page.

.ts code

this.api.updateProfile(myFormData).subscribe((resp: any) => {
      if (resp.status === false) {
          this.ts.error(resp.msg);
          return false;
      } else {
        window.location.reload();
        this.ts.success(resp.msg);
        return true
      }
    }

.html code

<div >
  <div >
    <button type="submit"  control-id="ControlID-8">
      <span >Update</span>
    </button>
  </div>
</div>

CodePudding user response:

Pretty simple

this.api.updateProfile(myFormData).subscribe((resp: any) => {
      if (resp.status === false) {
          this.ts.error(resp.msg);
          return false;
      } else {
        this.router.navigate(['/your-page name']).then(() => {
        window.location.reload();
      });
        this.ts.success(resp.msg);
        return true
      }
    })
    
    return false;
  }
  • Related