javascript - 造型角垫选择条件
问题描述
我正在使用<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>
解决方案
将样式应用于mat-select
和mat-option
。对于mat-select
,您可以使用selected
属性检查选择的值。您可以使用模板逻辑应用样式 -selectionChange
如果您不想使用事件,则不需要:
https://stackblitz.com/edit/angular-xgnq4k-743d3o?file=app/select-overview-example.html
<mat-select #select [style.font-weight]="select.value != 'default' ? 'bold' : 'normal'">
<mat-option *ngFor="let food of foods" [value]="food.value"
[style.font-weight]="food.value != 'default' ? 'bold' : 'normal'">
{{food.viewValue}}
</mat-option>
</mat-select>
推荐阅读
- linkedin - LinkedIn 网站分享始终显示 1 分钟阅读。有什么办法可以去掉标签吗?
- python - 如何通过发送 http 请求使用谷歌翻译
- python - 无法通过调用内部提交的存储过程来更新数据库
- anylogic - 带有动态事件的自定义流程图中的 Rack Pick
- r - R中的错误 - 列多于列名
- rust - 为什么开发依赖不能是可选的?
- docusignapi - 如何填写所有收件人 /Signer 并将工作流通过 API/Rest Web 服务移动到第二个签名者
- python - 如何将列表值与python中另一个列表中的另一个值对应起来
- python - 如何用拆分值分隔字典
- python-3.x - 根据一列的值过滤行并计算 Pandas 中总和的百分比