Hub*_*her 3 angular-material bootstrap-4 angular
我尝试用[innerHTML]里面<mat-option>的<mat-select>工作正常的下拉列表中,而不是选择的值。
版本:
在我的示例中,使用的代码是
<mat-form-field class="col-11">
<mat-select
[(ngModel)]="node.nodeType"
(change)="nodeTypeChanged()"
placeholder="{{'node.node_type' | translate}}"
[compareWith]="compareObjects">
<mat-option
*ngFor="let item of nodeTypes"
[value]="item">
<span [innerHTML]="item.iconVisual.iconCodeHtml"></span>
<span> {{item.label}}</span>
</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
附加的屏幕截图显示了问题,其中组合框未选择,其中未呈现任务图标,而所选组合框已正确呈现图标,显示了问题。
选定的组合框:图标未呈现
未选中的组合框:呈现所有图标
此处简化了stackblitz 。
这是一个错误还是我错过了什么?
正确答案是使用<mat-select-trigger>元素:
喜欢:
<mat-select-trigger>
<span [innerHTML]="nodeType.iconHtml"></span>
<span> {{ nodeType.label }}</span>
</mat-select-trigger>
Run Code Online (Sandbox Code Playgroud)
这是完整示例的外观:在线演示
template: `
<mat-form-field>
<mat-select [(ngModel)]="nodeType" placeholder="NodeType">
<mat-select-trigger>
<span [innerHTML]="nodeType.iconHtml"></span>
<span> {{ nodeType.label }}</span>
</mat-select-trigger>
<mat-option *ngFor="let item of nodeTypes" [value]="item">
<span [innerHTML]="item.iconHtml"></span>
<span> {{ item.label }}</span>
</mat-option>
</mat-select>
</mat-form-field>
`,
styles: [
`
h1 {
font-family: Lato;
}
`
]
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2457 次 |
| 最近记录: |