如何在结构指令中引用组件

时间:2018-01-03 17:48:56

标签: angular

我想制作一个特定于组件的结构指令,我还需要对该组件的引用。我试过这样:

Fn::Select

然后:

<mat-progress-spinner *progress></mat-progress-spinner>

但我明白了:

  

NullInjectorError:没有ComponentRef的提供者!

我也尝试过:

@Directive({ selector: '[progress]' })
export class ProgressDirective implements AfterViewInit {

  constructor(
    private componentRef: ComponentRef<MatProgressSpinner>,
    private viewContainer: ViewContainerRef
  ) { }

}

但是spinner未定义,即使在ngAfterViewInit中也是如此。

1 个答案:

答案 0 :(得分:-1)

您应该可以直接在<mat-progress-spinner>条件下使用*ngIf。确保在您的组件/指令中,您在progress-spinner上设置mode(optional)valuecolor

相关问题