ngOnDestroy is called when loading the page for the first time

Discussão em 'Angular' iniciado por purplefeel, Junho 19, 2025.

  1. purplefeel

    purplefeel Guest

    When I load the page first time, on some pages it shows unsubscribe error in ngOnDestroy as I am unsubscribing subscribes in it.

    I am not sure why ngOnDestroy is called at the init of the component.

    [​IMG]

    [​IMG]

    This is the error what I see when the page is first loaded.

    I thought this was some issue from angular2-multiselect-dropdown but in some other component, its own ngOnDestory is called as well and says subscription to unsubscribe is not defined.

    So I added if condition to remove the error message. [​IMG]

    This is the creation of the subscription.

    [​IMG] [​IMG]

    Actually I don't think it has any other problem in defining the observable.

    So is this a problem with angular component lifecycle or possibly an issue from angular2-multiselect-dropdown?

    I didn't see this error before and not sure what I did wrong. Can anyone had similar issue or help me on this? Thanks in advance.

    Continue reading...

Compartilhe esta Página