【问题标题】:adding html to the mat-optgroup label将 html 添加到 mat-optgroup 标签
【发布时间】:2019-02-26 04:43:16
【问题描述】:

是否可以使用 Angular Material 为自动完成组件的 optgroup 标签提供 HTML 模板,而不是将字符串绑定到 label 输入? label 属性转义任何 HTML 标记。

【问题讨论】:

    标签: angular angular-material


    【解决方案1】:

    我玩了一点,看起来你可以做到,你只需要删除[label]输入值并把你的 <mat-optgroup> 内的自定义模板 喜欢:

    <mat-autocomplete #autoGroup="matAutocomplete">
            <mat-optgroup *ngFor="let group of stateGroupOptions | async">
              <!-- here i put my custom button instead of label --->
              <button mat-raised-button color="primary">{{group.letter}}</button>
              <mat-option *ngFor="let name of group.names" [value]="name">
                {{name}}
              </mat-option>
          </mat-optgroup>
    </mat-autocomplete>
    

    stackblitz 上的示例(我使用按钮而不是普通标签)。希望对您有所帮助。

    【讨论】:

    • 感谢您的示例,它表明您放置在 标记内但不在 内的任何内容实际上都用作标签的内容!
    猜你喜欢
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多