How to Clear Observable Array in Angular


angular rxjs observable

For example, you have a simple observable data that you are getting from the store:

todos$ : Observable<any>;

constructor(private store : Store<any>) {
  this.todos$ = store.select("todos");
}

We can simply clean this array using the following code:

 this.todos$ = of([])

Operator of emits an empty array and return a new Observable. If you render todos$ using AsyncPipe it will show nothing.

Also, you can specify a type of returned value:

 this.todos$ = of(<any>[])
comments powered by Disqus