I am working on setting up a simple method to compare the current username with a profile's username in an Angular service.
It is necessary for the profile username and user's username to be resolved before they can be compared. How can I create a boolean observable to subscribe to this comparison in components?
This is the code I have so far:
public profileId = new Subject<string>; // Observable string source updated from a profile.component (when the URL displays the profile's username)
public profileId$ = this.profileId.asObservable();
public currentUser = this.principal.asObservable().distinctUntilChanged();
public isProfileOwner(): Observable<boolean> { // A function whose declared type is neither 'void' nor 'any' must return a value.
this.currentUser.subscribe(user => {
this.profileId$.subscribe(
profile => {
console.log(profile + ' ' + user.username); // match!
if (profile === user.username) {
return Observable.of(true);
} else {
return Observable.of(false);
}
}
)
})
}
Even though this is how other responses on SO suggest to achieve this, I am receiving the error
[ts] A function whose declared type is neither 'void' nor 'any' must return a value.
I would like to subscribe to this test in components.
this.authService.isProfileOwner().subscribe(
data => {
console.log(data); // should be boolean
}
)