Ionic-framework: ionViewDidLoad not called in custom component, but ngOnInit did get called

Created on 10 May 2017  路  6Comments  路  Source: ionic-team/ionic-framework

Ionic version: (check one with "x")
[ ] 1.x
[ ] 2.x
[x] 3.x

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
I have a custom component. Another page referenced this component by using of component selector, like <my-component></my-component>

First I put some initialization code in MyComponent:ionViewDidLoad, but I found it never got called, then I tried to put those code into ngOnInit(), it worked.
From the document, I supposed ionViewDidLoad and ngOnInit are same hook, the former is wrapper of latter

Expected behavior:

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

global packages:

    @ionic/cli-utils : 1.0.0
    Cordova CLI      : 6.5.0
    Ionic CLI        : 3.0.0

local packages:

    @ionic/app-scripts              : 1.3.5
    @ionic/cli-plugin-cordova       : 1.0.0
    @ionic/cli-plugin-ionic-angular : 1.0.0
    Ionic Framework                 : ionic-angular 3.1.0

System:

    Node       : v6.10.0
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.2 Build version 8E2002
    ios-deploy : 1.9.1
    ios-sim    : 5.0.13

Most helpful comment

AFAIK, Ionic lifecycle events are only fired on pages: things that interact with the navigation system. They are not fired on embedded components.

All 6 comments

AFAIK, Ionic lifecycle events are only fired on pages: things that interact with the navigation system. They are not fired on embedded components.

@rapropos if so, it would make sense, thanks for clarification

Thanks for the issue! Our lifecycle events are only set up to work with Ionic pages, as rapropos said. 馃檪

We have some documentation on this here: http://ionicframework.com/docs/api/navigation/NavController/#lifecycle-events

If you have ideas for how we could improve this documentation, please create an issue on our ionic-site repository.

i am not using ionic. i am building mobile app by using angular app with cordova plugins. but i want to use ionViewDidLeave() event ... where can i catch that event in normal angular app? @brandyscarney

@bharathnallamothu since you're not using Ionic, you never receive ionViewDidLeave then. You can check Angular component lifecycle events, https://angular.io/guide/lifecycle-hooks, ngOnDestroy in your case

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nick-The-Uncharted picture Nick-The-Uncharted  路  3Comments

giammaleoni picture giammaleoni  路  3Comments

Macstyg picture Macstyg  路  3Comments

masimplo picture masimplo  路  3Comments

alexbainbridge picture alexbainbridge  路  3Comments