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()
}
}