【发布时间】:2020-11-06 06:50:52
【问题描述】:
在我的 quiz app 中,我需要在选择一个选项后禁用 mat-radio-buttons。我在模板中的 mat-radio-buttons 上有 [disabled]="alreadyAnswered",在我的 TS 文件声明中有 alreadyAnswered = false;。选择选项后,在SetSelected(i)函数中设置了 this.alreadyAnswered = true;。一旦选择了一个选项,所有其他选项都应该被禁用并灰显。请你帮我解决这个问题。谢谢。
在 SingleAnswerComponent 模板中:
<div *ngIf="!multipleAnswer">
<div class="options" *ngFor="let option of currentQuestion.options; index as i">
<mat-radio-button (change)="setSelected(i)" [disabled]="alreadyAnswered" [class]="option.className">
<span i18n>{{ i + 1 }}. {{ option.text }}</span>
<ng-container>
<i class="material-icons feedback-icon" *ngIf="option.correct && isCorrectAnswerSelected">done</i>
<i class="material-icons feedback-icon" *ngIf="!option.correct">clear</i>
</ng-container>
</mat-radio-button>
【问题讨论】:
-
目前的结果是什么?究竟会发生什么?
-
现在单个答案中的所有选项都是可点击的,当我点击一个选项时,所有其他选项仍然可以点击,希望它禁用其他选项点击(灰色)。
-
我明白了。然后我们需要查看更多代码。该单选按钮是组件的一部分吗?所有按钮都在同一个组件内吗?否则,您将不得不使用服务与其他组件通信单击按钮(除非您已经拥有此功能?)。
-
是的,mat-radio-button 是 SingleAnswerComponent 的一部分(参见我上面的编辑),所有单选按钮都在同一个组件中。
标签: angular typescript