我正在将我的 ionic 2 应用程序迁移到删除 app.getComponent 的 RC 版本。在他们的 github 发布说明中,他们谈到了使用 ViewChild,我该如何正确使用它?
之前(在 RC 版本之前工作):
openPage(page) {
this.app.getComponent('leftMenu').close();
// navigate to the new page if it is not the current page
let nav = this.app.getComponent('nav');
nav.setRoot(page.component);
}
后:
@Component({
templateUrl: 'build/app.html',
queries: {
leftMenu: new ViewChild('leftMenu'),
nav: new ViewChild('content')
}
})
....
openPage(page) {
// close the menu when clicking a link from the menu
this.leftmenu.close();
// navigate to the new page if it is not the current page
this.nav.setRoot(page.component);
}
我试图获得“leftMenu”组件但没有任何成功。我得到的错误是
browser_adapter.js:77 原始异常:TypeError:无法读取未定义的属性“关闭”