0

I would like to give user the chance to hit cancel on a form. This component only has the form displayed. I would like to put the cancel button inside of the form so it sits next to the submit button, but when user triggers the cancel button, I want to change routes and display the about component.

Whenever I try any of these:

`
onCancel(){    
    return this.location.back();
  }
`

`
onCancel(){    
    return this.router.navigate(['/about']);
  }
`

`
<mat-card-actions>
      <button mat-raised-button [disabled]="!contactForm.valid" color="primary" type="submit">Submit</button>
      <button mat-raised-button color="warn" routerLink="/about">Cancel</button>
    </mat-card-actions>
`

The transition of the route is temporarily paused, the URL on the page changes to the correct path, however it appends a ? right after the about? path, and then after about 2 seconds it changes the route.

How can I include the cancel button in the form?

Here is what is happeningThe state in which the app is in when selecting cancel from within the form and changing routes

O.MeeKoh
  • 1,976
  • 3
  • 24
  • 53

1 Answers1

0

Just wanted to answer this question because Daniel W Strimpel figured it out. The problem was that I had not set explicitly the type on the cancel button. By default it was set to "type=submit", when I changed it to "type=button" it all worked as expected.

O.MeeKoh
  • 1,976
  • 3
  • 24
  • 53