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

前端 未结 3 1272
长发绾君心
长发绾君心 2021-01-07 20:31

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

I am getting the error create is deprecated: use

相关标签:
3条回答
  • 2021-01-07 20:54

    Pretty simple

    this.data$ = new Observable((observer: Observer) => {
      observer.next();
      observer.complete();
    });
    
    0 讨论(0)
  • 2021-01-07 21:10

    Or you can use just

    this.data$ = of(this.model);
    
    0 讨论(0)
  • 2021-01-07 21:13
    observableSubscription: Subscription;
    

    Creating Custom Observable

    const observer = new Observable((observer: Observer) => {
       observer.next();
       observer.error();
       observer.complete();
    });
    

    Subscribing To Custom Observable

    this.observableSubscription = observer.subscribe((data:any) => {
       console.log(data);
    })
    

    Unsubscribing

    this.observableSubscription.unsubscribe();
    
    0 讨论(0)
提交回复
热议问题