I have seen authServices where there is a boolean or user object and another component with a nav which displays different buttons depending on the log status.
So the service is injected in the component and observable is created in the authService so the component can subscribe to the boolean. My question is why using observable and not just using the already injected instance of the service:
<nav>
<ul *ngIf="!this.authService.isAuth">
<li><a routerLink="/home">Home</a></li>
<li><a routerLink="/login">Login</a></li>
</ul>
</nav>
from the already injected service:
constructor(private authService: AuthService) {
}
I have seen examples where the component subscribed to an observable in the auth service so it would be like:
isAuth: Observable<boolean> //in the authService
this.authService.isAuth.subscribe(x => this.isAuth= x)
Why using observable when you can do it the first way?