I know I can use {providedIn:'root'}
to declare my service at the root of the app, also I can add it in a component level or module level by using providers:[]
.
My concern here is that I use lazy loaded module and the service doesn't get destroyed as the module is still loaded in cache? So is there an alternative to initializing and detroying the service outside of the constructor and ngOnDestroy
method? so it get's destroyed when leaving the parent component?
perhaps using lazy loaded components that are standalone but I'm not sure?