尝试导入“间隔”时出现错误“无法读取未定义的属性'调用'”
我的进口是:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/merge';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/observable/interval';
如果我删除了最后一次导入,则效果很好。
我在控制台中遇到此错误
Uncaught TypeError:无法读取对象... / .. / .. / ..处eval(home.component.ts:12)处webpack_require(inline.bundle.js:55)处未定义的属性“调用” 。 /src/app/home/home.component.ts(main.bundle.js:134)在webpack_require(inline.bundle.js:55)在eval(app.module.ts:23)在Object ... /。 ./../../../src/app/app.module.ts(main.bundle.js:52)在webpack_require(inline.bundle.js:55)在eval(main.ts:4)在对象... / .. / .. / .. / .. / src / main.ts(main.bundle.js:394)位于webpack_require(inline.bundle.js:55)webpack_require @ inline.bundle.js: 55(匿名)@ home.component.ts:12 ../../../../../src/app/home/home.component.ts @ main.bundle.js:134 webpack_require@ inline.bundle.js:55(匿名)@ app.module.ts:23 ../../../../../src/app/app.module.ts @ main.bundle.js: 52 webpack_require @ inline.bundle.js:55(匿名)@ main.ts:4 ../../../../../src/main.ts @ main.bundle.js:394 webpack_require @内联.bundle.js:55 0 @ main.bundle.js:409 webpack_require @ inline.bundle.js:55 webpackJsonpCallback @ inline.bundle.js:26(匿名)@ main.bundle.js:1
更新我认为也许问题出在使用间隔?我尝试使用计时器如下,它工作。
import { timer } from 'rxjs/observable/timer';
var numbers = timer(5000);
numbers.subscribe(x => console.log(x));
但这会产生“无法读取未定义的属性'调用'”
import { interval } from 'rxjs/observable/interval';
var numbers = interval(1000);
numbers.subscribe(x => console.log(x));
管道运算符是导入和使用rxjs运算符的新的首选方式。有关更多信息,请参阅rxjs docs。
import { map, filter, scan } from 'rxjs/operators';
source$.pipe(
filter(x => x % 2 === 0),
map(x => x + x),
scan((acc, x) => acc + x, 0)
)
可以导入其他运算符(例如创建Observables)并直接使用:
import { combineLatest } from 'rxjs/observable/combineLatest';
combineLatest(this.first$, this.second$, (first, second) => ({first, second}))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句