I have a service this service should run until the project is started and closed. After the application (website) is closed, the ngOnDestroy() method of the service should run. How do I know if the ngOnDestroy() method in the service is working? Does this ngOnDestroy() work? export class UserServiceService implements OnDestroy { subsc: Subscription; constructor( private auth: AngularFireAuth, private db: AngularFireDatabase, private fnc: AngularFireFunctions, private router: Router, private tostr: ToastrService, ) { this.subsc = this.auth.authState.subscribe((user) => { if (user) { this.db.database .ref("users/" + user.uid + "/shopCart/") .on("value", (snap) => {}); } else { //not user } }); } ngOnDestroy(): void { console.log("Closed"); this.subsc.unsubscribe(); this.db.database.ref("users/" + this.currentUserId + "/shopCart/").off(); } } Continue reading...