I have an angular 2+ app running onsen ui, I have setup some components as pages and I am using the ons-navigator to switch between them.
The problem im having is that when im subscribed to an observable in an ons-page and the user navigates away from that page, The observable is still active. It seems like ngOndestroy doesnt get called when changing pages using the onsen navigator.
Im wondering how can I resolve this?
heres some code:
import { Component, OnDestroy, OnInit } from '@angular/core';
import { OnsNavigator } from 'ngx-onsenui';
import { HomePageComponent } from '../home-page/home-page.component';
import { CommonDataService } from '../_services/common-data.service';
import { MenuService } from '../_services/menu.service';
import { UserService } from '../_services/user.service';
@Component({
selector: 'ons-page',
templateUrl: './login-page.component.html',
styleUrls: ['./login-page.component.scss']
})
export class LoginPageComponent implements OnInit {
constructor(
private menuService: MenuService,
private commonDataService: CommonDataService,
private _navigator: OnsNavigator,
private userService: UserService) { }
ngOnInit() {
this.menuService.changePage$.subscribe((page) => {
this._navigator.element.pushPage(page, {data: {hoge: "fuga"}});
});
}
ngOnDestroy(): void {
//doesnt work
console.log('on destroy called.');
}
}