Property interval does not exist in the type observable

前端 未结 4 660
你的背包
你的背包 2020-12-09 08:42
ngAfterViewInit(){
     Observable.interval(3000).timeInterval().subscribe()=>{};    
}

Trying to invoke the Observable.interval() method it is

相关标签:
4条回答
  • 2020-12-09 09:26

    this is correct for angular 6.1.+ and rxjs 6.2.+

    import { Observable } from 'rxjs';
    import { interval } from 'rxjs';
    
     interval(1000).subscribe(
             (value: number) => {
               this.secondes = value;
             },
             (error: any) => {
               console.log('error');
             },
             () => {
               console.log('observable completed !');
             }
           );

    0 讨论(0)
  • 2020-12-09 09:28

    for rxjs 5.5.2+ it is:

    import { interval } from 'rxjs/observable/interval';
    

    usage:

    interval(3000).subscribe(x => // do something)
    
    0 讨论(0)
  • 2020-12-09 09:29
    import { Observable } from 'rxjs';
    import { interval } from 'rxjs';
    import { takeWhile } from 'rxjs/operators';
    
    // here 20 (secs) is a reference till when it will get completed
     interval(1000).pipe(takeWhile(value => value < 20)).subscribe(
             (value: number) => {
               this.secondes = value;
             },
             (error: any) => {
               console.log('error');
             },
             () => {
               console.log('observable completed !');
             }
           );
    

    This is a answer to how to unsubscribe.

    0 讨论(0)
  • 2020-12-09 09:32

    For RxJS 6+ the answer given by Tomasz Kula only applies when using the rxjs-compat package, which should only be used when in the process of converting an application from RxJS 5 to RxJS 6.

    Within RxJS 6+, use:

    import { interval } from 'rxjs';
    
    interval(3000).subscribe(x => /* do something */)
    

    Note that any Observable creation function that previously existed on the Observable type, should now be imported from 'rxjs'.

    0 讨论(0)
提交回复
热议问题