简体   繁体   English

实现2个组件,并在内部使用两个组件,就像角材料对其组件所做的一样

[英]Implementing 2 components and using both one inside another just like angular-material does with its component

I have recently came across with the angular-material module and I am a bit confused about how angular-material could have multiple component used one inside the other at the same place.Like the below 我最近遇到过角材料模块,我对角材料如何在同一个地方在彼此内部使用多个组件感到有些困惑。

<mat-drawer-container class="example-container">
  <mat-drawer mode="side" opened>Drawer content</mat-drawer>
  <mat-drawer-content>Main content</mat-drawer-content>
</mat-drawer-container>

How things work in this so nesting way. 事物如何以这种嵌套方式工作。 I need to know about how these multiple components contribute to accomplish the work. 我需要知道这些多个组成部分如何完成工作。

Use ng-content supports a select attribute that lets you project specific content in specific places. 使用ng-content支持select属性,该属性使您可以在特定位置投影特定内容。 This attribute takes a CSS selector (my-element, .my-class, [my-attribute], …) to match the children you want. 此属性采用CSS选择器(my-element,.my-class,[my-attribute]等)来匹配所需的子代。

<mat-drawer-container class="example-container">
  <mat-drawer mode="side" opened>Drawer content</mat-drawer>
  <mat-drawer-content>Main content</mat-drawer-content>
</mat-drawer-container>

Inside your mat-drawer-container.html use ng-content 在您的mat-drawer-container.html内部使用ng-content

<ng-content select='mat-drawer'></ng-content>
<ng-content select='mat-drawer-content '></ng-content>

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

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