Angular报错 类型“typeof Observable”上不存在属性“from” 类型observable上不存在属性debounceTime

在学习Angular过程中,由于按照视频Angular4学习的,代码报错:类型“typeof Observable”上不存在属性“from”,类型observable上不存在属性debounceTime

查资料发现,由于自己环境是Anguar8,"rxjs": "~6.4.0",响应式编程的语法已经有一些变化了。

Angular4 Observable用法:

Observable.from([1,2,3,4])
    .fliter(e => e%2 == 0 )
    .map(e => e*e)
    .subscribe(
      e => console.log(e),
      err => console.error(err),
      () => console.log("结束啦")
    )
  }

Angular8 Observable用法:

import { from } from 'rxjs';
import { filter, map } from 'rxjs/operators';
from([1, 2, 3, 4]).pipe(
      filter(e => e % 2 == 0),
      map(e => e * e)
    ).subscribe(
      e => console.log(e),
      err => console.error(err),
      () => console.log("结束啦")
    );

Angular4中debounceTime的用法

this.searchInput.valueChanges
      .debounceTime(500)
      .subscribe(stockCode => this.getStockInfo(stockCode));

Angular8中debounceTime的用法

import { debounceTime } from 'rxjs/operators';
this.searchInput.valueChanges
      .pipe(debounceTime(500))
      .subscribe(stockCode => this.getStockInfo(stockCode));

 

你可能感兴趣的:(Angular,Angular,响应式编程)