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

Need to redirect to another page after submit in Angular

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

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

<div class="form-group form-button mb-1">
                      <div class="form-group form-button mb-1">
                        <button type="submit" class="btn btn-primary btn-lg px-5" control-id="ControlID-8">
                          <span class="text-white">Update</span>
                        </button>
                      </div>
                    </div>
)

>Solution :

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