I have NGXS selector in SomeService
@Select(state => state.sample)
public sample$: Observable<Sample>;
I am using it inside an Angular RouteGuard like this
getSample(): boolean {
this.someService.sample$.subscribe({
next: (sample: Sample) => {
if (isValid(sample)) {
return true;
} else {
return false;
}
},
error: () => {
return false;
}
});
}
canActivate(): boolean {
return this.getSample();
}
I am getting an error 'A function whose declared type is neither 'void' nor 'any' must return a value'. I know the cause because it did not return anything outside subscribe, but I want to return only upon executing subscribe.