[英]Use app.component function in a page ionic 2
I am trying to use app.component.ts
function in a page, but getting error . 我正在尝试在页面中使用app.component.ts
函数,但出现错误 。
EXCEPTION: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'e.pages.updatePages')
Function in app.component.ts : app.component.ts中的功能:
updatePages(pages){
console.log(pages);
}
Code in page.ts page.ts中的代码
this.sidebarpage = [{ title: 'My Account', component: MyAccountPage }];
this.pages.updatePages(this.sidebarpage);
Already imported component in page.ts and added @ViewChild(MyApp) pages: MyApp;
已在page.ts中导入组件并添加了@ViewChild(MyApp) pages: MyApp;
app.component.ts is not a child page. app.component.ts不是子页面。 ViewChild decorator is used when you are accessing a child component set in your corresponding html page and there is generally no need to use root tags in other pages. 当您访问相应的html页面中的子组件集时,将使用ViewChild装饰器,并且通常无需在其他页面中使用根标签。
You should create a provider class for this. 您应该为此创建一个提供程序类。 Set the function in the provider and set the class in providers array app.module.ts to use in your components. 在提供程序中设置功能,并在提供程序数组app.module.ts中设置类以在组件中使用。 More here 这里更多
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.