I want to try to make a comparison in my component by using if(success) displayMessage else redirectToPage in 3 seconds. But, how can I check this *(this.link$.source.value.success) or (this.link$.getValue()) * if it send NULL. I try display in my console browser this.link$, it's display the BehaivorSubject. I try with a method getValue() it's not work. Can you please help me.
Thanks again
Browser console.log
Service.ts
private objectRes: BehaviorSubject<ResModel>;
public activationOrResetResponse: Observable<ResModel>
constructor(
public _apiService: ApiService,
) {
super(_apiService);
this.objectRes = new BehaviorSubject(null) as BehaviorSubject<ResModel>;
this.activationOrResetResponse = this.objectRes.asObservable();
}
public activateOrResetAccount(token: string, typeRoute: string): void {
this._apiService.get(this.type + "/" + typeRoute + "/" + token).subscribe(
(res) => {
this.activationOrReset = res;
this.objectRes.next(this.activationOrReset);
},
(error) => {
this.activationOrReset = error;
this.objectRes.next(this.activationOrReset);
}
);
}
Component.ts
public link$: Observable<ResModel>;
constructor(
private _authUserService: AuthUserService,
private _activeRoute: ActivatedRoute,
) {}
ngOnInit(): void {
this.getActivationPage();
}
public getActivationPage(): void {
this.link$ = this._authUserService.activationOrResetResponse;
this._authUserService.activateOrResetAccount(
this._activeRoute.snapshot.params.token,
"confirmation"
);
console.log("link$: ", this.link$.getValue()); // null ???????
}