角路由器-路由到奇怪的路由“?mat-radio-group-0 = true”

时间:2020-05-25 07:06:20

标签: angular typescript angular-material angular-routing radio-group

我的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 这种奇怪的事情在哪里发生?

1 个答案:

答案 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>