<ng-container *ngIf="question.questionType == 4">
<ng-container *ngFor="let answer of question.answers">
<button
(click)="setanswer(answer.answerId)"
[value]="answer.isSelected"
class="me-2"
name="{{ answer.answerId }}">{{ answer.answerDescription }}
</button>
</ng-container>
</ng-container>发布于 2022-07-10 16:31:41
您有很多替代方案,假设您定义了这个css类:
.primary {
background-color: green;
}<!-- 1) Property Binding -->
<button [class.primary]="answer.isSelected"></button>
<!-- 2) NgClass -->
<button [ngClass]="{ 'primary': answer.isSelected }"></button>
<!-- 3) ngStyle-->
<button [ngStyle]="{ 'background-color': answer.isSelected ? 'green' : 'blue' }"></button>Sidenote,在您的按钮HTML定义中,您需要为name而不是string interpolation使用属性绑定,所有html属性都可以在Angular中使用property binding。
<button
(click)="setanswer(answer.answerId)"
[value]="answer.isSelected"
class="me-2"
[name]="answer.answerId">{{ answer.answerDescription }}
</button>https://stackoverflow.com/questions/72929021
复制相似问题