I've been attempting to link an Observable to a template variable in Angular using the following code:
[class.active]="isBookmarked$ | async"
During the ngOnInit function, I initialize the Observable:
var promise = this.cacheService.getItem(this.bookmarkId).then(() => {
return true;
}).then(() => {
return false;
});
this.isBookmarked$ = Observable.fromPromise(promise);
Everything works as expected upon loading the page. However, when I add or remove an item, the template fails to detect the changes.
this.cacheService.removeItem(this.bookmarkId).then(() => { });
// or
this.cacheService.saveItem(this.bookmarkId, true, "bookmarks").then(() => { });
I have experimented with various Observables and even attempted using a Promise without converting it to an Observable, but unfortunately, I haven't been able to resolve the issue.