在动态调用组件中查看子组件

时间:2018-04-20 09:27:17

标签: angular viewchild router-outlet

我有从其他组件在router-outlet中调用的组件。在视图中,此组件显示为弹出窗口。在这个组件中,我有一个可以被View子访问的子组件。问题是 - 当我尝试调用子组件方法时,我收到'... 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

时的样子

0 个答案:

没有答案