Angular: create is deprecated: use new Observable() instead

mruanova picture mruanova · Apr 5, 2019 · Viewed 12.1k times · Source

I recently updated my version of angular using ng update and when running ng lint

I am getting the error create is deprecated: use new Observable() instead

this.data$ = Observable.create(t => {
    t.next(this.model);
    t.complete();
});

What is the syntax for new observable?

Answer

Sergey picture Sergey · Apr 5, 2019

Pretty simple

this.data$ = new Observable((observer: Observer) => {
  observer.next();
  observer.complete();
});