I generate a new project and tried all lifecycle events (ionViewDidLoad …) in app.component.ts but still fail. The events do not fire.
Ionic info:
Cordova CLI: 6.5.0
Ionic Framework Version: 2.2.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.4
ios-deploy version: 1.9.1
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v6.9.5
Xcode version: Xcode 8.2.1 Build version 8C1002
Those events are for Ionic
pages (called via setRoot
or push
in the NavController
), from what I know, and won’t work with app.component
nor with custom components (sub-components inside pages). You can still use ngOnInit
and other Angular
events.
See more here:
@Koleman The lifecycle hook ionViewDidLoad() and the likes works only on Ionic pages (the ones you call with NavController.push() and NavController.setRoot()). The angular events like ngOnInit() works though.
If you want the ionic page events, you can inject the ViewController and subscribe to its observables:
import { Component } from '@angular/core';
import { ViewController } from 'ionic-angular';
@Component({
selector: 'net-tree',
templateUrl: 'net-tree.html'
})
export class NetTree {
…