简体   繁体   English

在网页ionic 2中使用app.component函数

[英]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.

相关问题 如何在app.component外使用带有router-outlet的Angular 9导航栏 - How to use Angular 9 navigation bar with router-outlet outside the app.component 如何将属性从一个组件绑定到角度为4的App.Component? - How to Bind Property from one component to App.Component in angular 4? Angular Material sidenav指令在app.component中不起作用 - Angular Material sidenav directive does not work in app.component 为什么不在app.component中工作而在auth.guard中工作呢? - Why not working in app.component but in auth.guard? Angular不呈现HTML中来自app.component的值 - Angular not rendering value from app.component in HTML Angular Service将变量值传递给app.component - Angular Service passing variable value to app.component 如何将 app.component 的数据存储在 angular 中? - How to store data from app.component in angular? 如何在 app.component 的 Angular 中检测当前活动的父布局组件? - How to detect which parent layout component currently active in Angular in app.component? 如何在GeocoderService中存储来自geocoder.geocode()的地址并将其返回给app.component? - How to store address from geocoder.geocode() in GeocoderService and return it to app.component? 当我点击 angular 中 app.component 中的导航栏时,到达我的路由器插座的 div - Reach the div of my router-outlet when I click on the navigation bar in the app.component in angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM