我尝试在页面中使用 app.component.ts
函数,但收到错误。
EXCEPTION: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'e.pages.updatePages')
app.component.ts中的函数:
updatePages(pages){
console.log(pages);
}
page.ts中的代码
this.sidebarpage = [{ title: 'My Account', component: MyAccountPage }];
this.pages.updatePages(this.sidebarpage);
已在 page.ts 中导入组件并添加 @ViewChild(MyApp) 页面:MyApp;
最佳答案
app.component.ts 不是子页面。 ViewChild装饰器是在访问对应html页面中设置的子组件时使用的,一般不需要在其他页面中使用根标签。
您应该为此创建一个提供程序类。 在提供程序中设置函数,并在提供程序数组 app.module.ts 中设置类以在组件中使用。 More here
关于javascript - 在页面 ionic 2 中使用 app.component 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41235177/