Angular 2,调用未定义的子组件

Angular 2,调用未定义的子组件,angular,ionic2,Angular,Ionic2,我在我的爱奥尼亚应用程序中有一个全局页脚,我是这样做的。我在ion导航中添加了选择器组件,它工作得很好。我的页脚显示在每一页上 在app.html中 <ion-nav [root]="rootPage" #content swipeBackEnabled="false"> </ion-nav> <call-footer #CallChild></call-footer> 但是,我发现无法读取未定义的属性“test” 我不确定是否有语法错误或我缺

我在我的爱奥尼亚应用程序中有一个全局页脚,我是这样做的。我在ion导航中添加了选择器组件,它工作得很好。我的页脚显示在每一页上

在app.html中

<ion-nav [root]="rootPage" #content swipeBackEnabled="false">

</ion-nav>
<call-footer #CallChild></call-footer>
但是,我发现无法读取未定义的属性“test”


我不确定是否有语法错误或我缺少一些想法。如何解决此问题?

查看儿童
返回
ElementRef
。你不能调用这样的函数

解决方法是使用爱奥尼亚的
事件

将您的功能更改为:

ngAfterViewInit() {
   this.events.publish("child:test");
}
在您的子页面中:

constructor(events: Events) {
  events.subscribe("child:test", ()=> {
     this.test();
  });
}

test() { console.log("test called"); }

另外,有关更详细的解释,请参阅我在此处的回答。
@ViewChild
返回一个
ElementRef
。你不能调用这样的函数

解决方法是使用爱奥尼亚的
事件

将您的功能更改为:

ngAfterViewInit() {
   this.events.publish("child:test");
}
在您的子页面中:

constructor(events: Events) {
  events.subscribe("child:test", ()=> {
     this.test();
  });
}

test() { console.log("test called"); }

另外,有关更详细的解释,请参阅我在此处的回答

your calls.html是什么样子的?我编辑过。这是calls.html我看不到calls.html。有一个app.htmlth下面的代码是calls.html。也许编辑仍然没有刷新,那不是html。是ts文件你的calls.html是什么样子的?我编辑过。这是calls.html我看不到calls.html。有一个app.htmlth下面的代码是calls.html。也许编辑仍然没有刷新,那不是html。这是ts文件嗨,跟进问题。我正在尝试类似的东西//callspage this.events.publish(“child:initializefooter”,this)//footer events.subscribe(“child:initializefooter”,(page)=>{this.ModalExitCall=page;this.ModalExitCall.present();//打开模型。Getting Error://找不到[object object]}的组件工厂)是否有办法将输入参数强制转换为组件?目前在我的手机上,但请查看Angular的
输出
参数。您将能够使用它们调用函数HI,跟进问题。我正在尝试类似的东西//callspage this.events.publish(“child:initializefooter”,this)//footer events.subscribe(“child:initializefooter”,(page)=>{this.ModalExitCall=page;this.ModalExitCall.present();//打开模型。Getting Error://找不到[object object]}的组件工厂)是否有办法将输入参数强制转换为组件?目前在我的手机上,但请查看Angular的
输出
参数。您可以使用它们调用函数