【发布时间】:2020-01-24 15:28:51
【问题描述】:
我正在使用<mat-select>,并且我希望在条件为真时有一些带有粗体样式的选项。
目前,下拉选项中的选项是粗体的,但是一旦选择了选项,样式就不会应用于文本字段中的选择。
如何在选择后将样式应用到文本字段?
这是一个代码示例:
<mat-form-field>
<mat-label><span translate="entities.annexe"></span></mat-label>
<mat-select [(ngModel)]="p.annexe" formControlName="annexe">
<mat-option *ngFor="let annexe of annexesEnums()" [value]="getNameFromValue(annexe)">
<span [style.font-weight]="annexe != 'Default' ? 'bold' : 'normal'">{{annexe}}</span>
</mat-option>
</mat-select>
</mat-form-field>
【问题讨论】:
-
您的代码发生了其他未显示的事情。
<span [style.font-weight]="'bold'">适用于选定或未选定的列表项。你有任何其他风格,也许是全球定义的? -
'!=' 应替换为 '!=='
-
不是这样 - 这很好用:stackblitz.com/edit/angular-2v4nt7?file=app/…
-
如果您希望在选择后将该样式应用于所选值,则必须将其应用于选择本身。将 [style.font-weight]="annexe != 'Default' ? 'bold' : 'normal'" 应用于 mat-select 应该可以做到。请参考-stackblitz.com/edit/angular-xgnq4k?file=app/…
-
@G.Tranter your stackblitz shows exactly what i'm facing, indeed, it is bold in the dropdown, but I would like it to stay bold in the input, when the select is no longer focused .
标签: javascript html css angular angular-material