当从执行路线更改的表单中触发取消按钮时,组件更改会暂时暂停吗?

时间:2019-04-13 18:12:12

标签: angular

我想让用户有机会在表单上点击“取消”。该组件仅显示表格。我想将“取消”按钮放在表单内,使其位于“提交”按钮旁边,但是当用户触发“取消”按钮时,我想更改路线并显示“关于”组件。

只要我尝试以下任何一种方法

`
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>
`

该路由的过渡暂时暂停,页面上的URL更改为正确的路径,但是它附加了一个?在大约之后?路径,然后在大约2秒钟后更改路线。

如何在表单中包含“取消”按钮?

这是正在发生的事情The state in which the app is in when selecting cancel from within the form and changing routes

1 个答案:

答案 0 :(得分:0)

只想回答这个问题,因为Daniel W Strimpel知道了。问题是我没有在取消按钮上明确设置类型。默认情况下,它设置为"type=submit",当我将其更改为"type=button"时,一切正常。