provider.ngAfterViewInit 不是 Angular 中使用 ngIf 的函数?

provider.ngAfterViewInit is not a function in Angular using ngIf?

有组件被 ngIf 激活:

 <filter-dialog *ngIf="isFilterOpen()"></filter-dialog>

其中:

  isFilterOpen() {
    return FilterService.isOpen;
  }

组件 class 是:

export class FilterDialogComponent implements AfterViewInit {
    ngAfterViewInit() {
    this.createFilterComponent();
  }
}

为什么我会出现这个错误:

SkeletonComponent.html:13 ERROR TypeError: provider.ngAfterViewInit is not a function
    at callProviderLifecycles (core.js:32327)
    at callElementProvidersLifecycles (core.js:32292)
    at callLifecycleHooksChildrenFirst (core.js:32274)
    at checkAndUpdateView (core.js:44280)
    at callViewAction (core.js:44636)
    at execEmbeddedViewsAction (core.js:44593)
    at checkAndUpdateView (core.js:44271)
    at callViewAction (core.js:44636)
    at execComponentViewsAction (core.js:44564)
    at checkAndUpdateView (core.js:44277)

createFilterComponent 是:

  createFilterComponent() {
    const concreteFilterForm = this.filterService.form;
    const concreteFilterComponent = FilterLinkReferenceDialogComponent;

    /* Factory angular */

    const factory = this.resolver.resolveComponentFactory(
      concreteFilterComponent
    );

    this.componentRef = this.viewContainerRef.createComponent(factory);
    this.componentRef.instance.form = concreteFilterForm;
  }

尝试将您的 FilterService.isOpen 设置为 true:

createFilterComponent() {        
    /* The code is omitted for the brevity */
    FilterService.isOpen = true;
}

此外,请尝试通过 ng serve

重新启动您的应用程序