0

我有从其他组件在路由器插座中调用的组件。在视图中,此组件显示为弹出窗口。在这个组件中,我有 View child 可以访问的子组件。问题是-当我尝试调用子组件方法时,我收到'... of UNDEFINED ...'。在调查时我注意到, ViewChild 是在创建 View 之前设置的,所以我们只是没有创建子组件。

这是弹出组件的打开方式:

<tyc-side-bar [active]="isSidebarOpen" (onClose)="closeSidebar()" id="sidebar-schedule-closing" customClass="sidebar--schedule-closing">
  <router-outlet></router-outlet>
</tyc-side-bar>

openEditClosing() {
    this.isSidebarOpen = true;
    this.router.navigate(['./edit'],
    {
        relativeTo: this.route,
        skipLocationChange: true
    });
}

在弹出组件中查看子项。发射 setter 时 V 为空。在弹出组件 html 子组件被声明为标签:

  @ViewChild(ClosingGeneralSettingsComponent) _generalSettingsComponent: ClosingGeneralSettingsComponent;

  public get generalSettingsComponent(): ClosingGeneralSettingsComponent {
    return this._generalSettingsComponent;
  }
  public set generalSettingsComponent(v: ClosingGeneralSettingsComponent) {
    this._generalSettingsComponent = v;
  }


<tyc-closing-general-settings [isScheduleMode]='false' [isEscrow]='isEscrow'></tyc-closing-general-settings>

PS:这是设置 ViewChild 时的样子http://webdav.chisw.us/webdav/TYC.Web__-_Google_Chrome_2018-04-20_12.47.13.png

4

0 回答 0