I am using sidemenu
template and I want to call a function in root page
( in my case, app.component.ts
) from child page
(page1.ts for example).
I tried to use @output
:
page1.ts
@Output() triggerHeader = new EventEmitter();
...
this.triggerHeader.emit(true);///<-- trigger the action
then add the (triggerHeader)
to the app.html
:
<ion-header *ngIf="headered" (triggerHeader)="childTriggerHeader($event)">
and it did not work.
How can I resolve this?
The best approach to do this is to create service and share it between two components(page1 and app.component) add Subject
to service and fire-catch it. please read further -> http://blog.angular-university.io/how-to-build-angular2-apps-using-rxjs-observable-data-services-pitfalls-to-avoid/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.