简体   繁体   English

如何在材质树组件内渲染 angular 组件

[英]How to render an angular component inside a material tree component

I'm trying to use angular material tree combined with checkbox, but instead of using pure text to the side of the checkbox, I want to render my own angular component.我正在尝试使用 angular 材质树与复选框相结合,但我不想在复选框的一侧使用纯文本,而是要渲染我自己的 angular 组件。

upon selection the model of that component should be emitted.选择后,应发射该组件的 model。

I've tried to use the following as a reference: https://stackblitz.com/angular/poxkygvnbyd?file=app%2Ftree-checklist-example.ts我尝试使用以下内容作为参考: https://stackblitz.com/angular/poxkygvnbyd?file=app%2Ftree-checklist-example.ts

And also tried reading the angular material tree API: https://material.angular.io/components/tree/api还尝试阅读 angular 材料树 API: https://material.ZD18B8624A0F5F5F721DAZDD7B823

Still not sure how it can be done.仍然不确定如何完成。

Use template logic to conditionally display the custom component inside the checkbox element:使用模板逻辑有条件地在复选框元素内显示自定义组件:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM