【问题标题】:Use app.component function in a page ionic 2在 ionic 2 页面中使用 app.component 函数
【发布时间】:2017-05-05 05:56:51
【问题描述】:

我正在尝试在页面中使用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) pages: MyApp;

【问题讨论】:

    标签: javascript angularjs angular typescript ionic2


    【解决方案1】:

    app.component.ts 不是子页面。 ViewChild装饰器用于访问对应html页面中设置的子组件,其他页面一般不需要使用root标签。

    您应该为此创建一个提供程序类。 在提供程序中设置函数并在提供程序数组 app.module.ts 中设置类以在您的组件中使用。 More here

    【讨论】:

    • 感谢您的回复。但是我已经在组件中定义了一些侧边栏菜单。现在我想在登录后在同一个数组中再添加一项。
    • 我只是想在另一个页面中使用组件功能。
    猜你喜欢
    • 2017-09-11
    • 2018-10-30
    • 2016-07-06
    • 2017-03-08
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多