【问题标题】:How to render an angular component inside a material tree component如何在材质树组件中渲染角度组件
【发布时间】:2020-01-31 22:41:45
【问题描述】:

我正在尝试将角度材质树与复选框结合使用, 但我不想在复选框的一侧使用纯文本,而是要呈现我自己的角度组件。

选择后,应发出该组件的模型。

我尝试使用以下内容作为参考: https://stackblitz.com/angular/poxkygvnbyd?file=app%2Ftree-checklist-example.ts

还尝试阅读角度材质树 API: https://material.angular.io/components/tree/api

仍然不确定如何做到这一点。

【问题讨论】:

    标签: angular angular-material


    【解决方案1】:

    使用模板逻辑在复选框元素内有条件地显示自定义组件:

    <mat-checkbox #cb class="checklist-leaf-node"
        [checked]="checklistSelection.isSelected(node)"
        (change)="checklistSelection.toggle(node);">
      <my-special-component *ngIf="cb.checked; else notChecked"></my-special-component>
      <ng-template #notChecked>{{node.item}}</ng-template>
    </mat-checkbox>
    

    【讨论】:

      猜你喜欢
      • 2021-10-15
      • 2022-10-14
      • 2022-07-26
      • 2020-03-10
      • 2021-03-05
      • 1970-01-01
      • 2019-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多