【发布时间】:2018-12-14 22:18:06
【问题描述】:
我是 Angular 的新手,我现在正在使用 Angular 开发离子应用程序,我的要求是使用事件发射器从子页面到父页面进行通信(只想从子页面更改父页面标题,我的代码如下,请建议我如何我这样做),我什至不知道这个概念有人可以帮助我吗
parent.html:-
<ion-header>
<ion-navbar>
<button menuToggle left>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>{{title}}</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
</ion-content>
parnet.ts:
export class Parent{
title:string;
getNotification(evt) {
this.title = ""+evt;
}
}
child.html:
<ion-content padding>
<h2>Grocery Page</h2>
<button ion-button (click)="sendNotification()" color="secondary" full>Notify my parent!</button>
</ion-content>
child.ts:
export class Child{
@Output() notifyParent: EventEmitter<any> = new EventEmitter();
sendNotification() {
this.notifyParent.emit('Parent Page');
}
}
【问题讨论】:
-
子元素名称是什么
-
我更新了我的代码,请立即查看
-
仍然没有发布子组件选择器
-
我更新了,请立即查看