I am trying to access the localStorage using Angular 4 and look for changes in the localStorage values using the Observables:
Here's the code I have been working on:
userNameObservable: Observable<string>;
userName: String = '';
ngOnInit() {
this.userNameObservable = Observable.create(
Observable.of(localStorage.getItem('profileName'))
);
this.userNameObservable.subscribe((name: String) => {
this.userName = name;
})
}
but I am getting an error ERROR TypeError: this._subscribe is not a function
. How do I resolve this? Is there a better and efficient way to look for changes in localStorage?