I am trying to change the login status after the user login
component.ts
isLoggedIn$: Observable<boolean>;
constructor (private auth:Auth){}
ngOnInit (){
this.isLoggedIn$ = this.auth.getUser()
console.log(this.isLoggedIn$);
}
Auth.ts
@Injectable()
export class Auth {
private user:boolean = false;
setUser(){
this.user= true;
}
getUser(){
return this.user
}
removeUser(){
this.user = false;
}
}
But i got the following error
error TS2322: Type 'true' is not assignable to type 'Observable'
Observableofbooleanvalue but returning just abooleanvalue. This code will make more sense if you are returningObservablefrom ahttpcall which maps to abooleanvalue asynchronously.httpservice withAuthclassObservable.of(this.user)isLoggedIn$in your template? If so, you can use it like*ngIf="isLoggedIn$ | async"