javascript - 在页面 ionic 2 中使用 app.component 函数

标签 javascript angularjs angular typescript ionic2

我尝试在页面中使用 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/

相关文章:

javascript - bing map 巴林的过境路线

javascript - 在构建 ajax 应用程序时放弃 <form> 标记是否合适?

javascript - 该指令从不重新加载其内容

javascript - 自定义指令中未定义的 ng-model 值

javascript - 如何在angular js中使用if语句条件

angular - 找不到命名空间

javascript - jspdf.addHTML 抛出错误

angularjs - 在另一个服务中使用 ActivatedRoute

javascript - webRTC:稍后添加音频或使用 peerJS 禁用麦克风

javascript - 我如何对我的数据关闭 ="modal"产生两种效果;一个重新加载父页面,而另一个不加载