Angular 角度2+;:将组件用作另一个组件中的输入

Angular 角度2+;:将组件用作另一个组件中的输入,angular,typescript,angular-directive,angular-components,Angular,Typescript,Angular Directive,Angular Components,如何使用组件作为角度模式中另一个组件的输入数据 例如: 我想要bulid表组件AppTableComponent: <app-table [dataSource]="dataSource" [columns]="columns"> <ng-container tableColumnDef="actions"> <a routerLink="/model/edit/{{item.id}}" routerLinkActive="active">Edit

如何使用组件作为角度模式中另一个组件的输入数据

例如:

我想要bulid表组件AppTableComponent:

<app-table [dataSource]="dataSource" [columns]="columns">
  <ng-container tableColumnDef="actions">
    <a routerLink="/model/edit/{{item.id}}" routerLinkActive="active">Edit</a>
    <a routerLink="/model/delete/{{item.id}}" routerLinkActive="active">Delete</a>
  </ng-container>
  <ng-container tableColumnDef="isActive">
    <div [ngClass]="{cercl:true, 'is-active':item.is_active}">&nbsp;</div>
  </ng-container>
</app-table>
请不要建议我使用角材料表组件。我不需要桌子。我只是想学点新东西


我会收集关于这个主题的任何信息或文章

如果要管理消费者零件上的模板,则必须使用角度嵌入式视图(
ng template
)。这就是material在其表实现中使用的内容

<table mat-table [dataSource]="dataSource">
  <ng-container matColumnDef="position">
    <th mat-header-cell *matHeaderCellDef> No. </th>
    <td mat-cell *matCellDef="let element"> {{element.position}} </td>
  </ng-container>
还有一些指令帮助程序,如:

@Directive({selector: '[headerRowOutlet]'})
export class HeaderRowOutlet implements RowOutlet {
  constructor(public viewContainer: ViewContainerRef,
              public elementRef: ElementRef) { }
}
因此,我们可以使用低级api基于嵌入式模板创建元素,例如
ViewContainerRef.createEmbeddedView(templateRef)
,但可以在这里找到简单的实现:


您可以使用
@ContentChild('tableHeader')标题:TemplateRef作为参考

您熟悉吗?
<table mat-table [dataSource]="dataSource">
  <ng-container matColumnDef="position">
    <ng-template matHeaderCellDef>
      <th mat-header-cell> No. </th>
    </ng-template>
    <ng-template matCellDef let-element="$implicit">
      <td mat-cell> {{element.position}} </td>
    </ng-template>
  </ng-container>
<ng-container headerRowOutlet></ng-container>
<ng-container rowOutlet></ng-container>
<ng-container footerRowOutlet></ng-container>
@Directive({selector: '[headerRowOutlet]'})
export class HeaderRowOutlet implements RowOutlet {
  constructor(public viewContainer: ViewContainerRef,
              public elementRef: ElementRef) { }
}
 <ng-template [ngTemplateOutlet]="header"></ng-template>
 <ng-template [ngTemplateOutlet]="body"></ng-template>
<compoent-selector>
     <ng-template #tableHeader></ng-template>
     <ng-template #body></ng-template>
</component-selector>