Angular 7 Cdk:没有使用CdkPortal的实例

时间:2019-01-02 06:01:14

标签: angular angular-cdk

我正在尝试实现一个简单的门户网站示例。 我的课看起来像这样:

@Component({
  selector: 'app-action-button',
  template: `
    <ng-template cdkPortal>
      <ng-content></ng-content>
    </ng-template>
  `
})
export class ActionButtonComponent implements AfterViewInit, OnDestroy {

  @ViewChild(CdkPortal)
  private portal: CdkPortal;

  // other code here

  ngAfterViewInit(): void {
    console.log(this.portal);
  }
}

我也尝试过:

<ng-container *cdkPortal>
    <ng-content></ng-content>
</ng-container>

但是无论我做什么,console.log(this.portal);总是打印“未定义”。

欢迎提供任何有关如何正确实例化“ portal”变量的建议!

可以找到here

0 个答案:

没有答案