我的HTML模板中有一个关闭按钮,它会在组件中触发close()函数: HTML模板:
<div>
<label id="radio-group-label">Please specify: </label>
<mat-radio-group
fxLayout="row"
aria-labelledby="radio-group-label"
class="radio-group"
formControlName="flWholeDay"
>
<mat-radio-button [checked]="wholeDayLeave" value="true"
>Whole day</mat-radio-button
>
<mat-radio-button [checked]="!wholeDayLeave" value="false"
>Part day</mat-radio-button
>
</mat-radio-group>
</div>
HTML按钮:
<button mat-raised-button fxLayoutAlign="center center" color="accent" (click)="close()">Close</button>
组件:
close() {
this.router.navigate(['/something']);
}
问题是,当按下按钮时,它会路由到http://localhost:4200/something?mat-radio-group-0=true 这种奇怪的事情在哪里发生?
答案 0 :(得分:1)
button
元素具有一个type
属性,默认为"submit"
。 (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button)
将type="button"
添加到您的按钮。
<button type="button" mat-raised-button fxLayoutAlign="center center" color="accent" (click)="close()">Close</button>