【发布时间】:2019-09-30 19:57:40
【问题描述】:
我有一个单选按钮 - 如果它被选中,它应该显示带有选项 1 和选项 2 的 mat-radio-group。mat-radio-group 按预期隐藏 - 但是,默认情况下,在启动我的应用程序时,所有单选按钮都被选中并且我无法取消选中其中任何一个。
我显然希望它们在启动时都未选中,这是/应该是默认行为。我做错了什么让他们默认检查?
Dialog.component.html
<mat-radio-button (click)="toggleDisplay('options')" class="item">See options</mat-radio-button>
<mat-radio-group *ngIf="doShow('options')" class="item-container">
<mat-radio-button class="item">Option 1</mat-radio-button>
<mat-radio-button class="item">Option 2</mat-radio-button>
</mat-radio-group>
</mat-radio-group>
Dialog.component.ts
currentlyShown = '';
toggleDisplay(element: string) {
this.currentlyShown = element;
}
doShow(element: string): boolean {
return this.currentlyShown === element;
}
提前致谢。 (已排除所有不必要的代码)
【问题讨论】:
-
请提供 Stackblitz
-
单选按钮有值。如果您不提供,则会对其进行检查。