[英]Rx.Observable.prototype.skip is undefined
I have Angular 2 application with the following code: 我有Angular 2应用程序,代码如下:
nextPage() {
this.currentPage += 1;
this.files = this._rawFiles
.skip((this.currentPage - 1) * 100)
.take(100);
}
It returns the following error: 它返回以下错误:
ORIGINAL EXCEPTION: TypeError: this._rawFiles.skip is not a function
this._rawFiles
is produced by Angular's Http
service, so it's supposed to use RxJS. this._rawFiles
由Angular的Http
服务生成,所以它应该使用RxJS。 Here's what it looks like when printed to the console: 这是打印到控制台时的样子:
It seems to be an Observable, but only a few methods are present. 它似乎是一个Observable,但只有少数方法存在。 Why isn't
Rx.Observable.prototype.skip(count)
in there? 为什么不在
Rx.Observable.prototype.skip(count)
?
Here's what a relevant part of package.json
looks like: 这是
package.json
的相关部分:
"dependencies": {
"@angular2-material/button": "^2.0.0-alpha.1",
"@angular2-material/card": "^2.0.0-alpha.1",
"@angular2-material/checkbox": "^2.0.0-alpha.1",
"@angular2-material/core": "^2.0.0-alpha.1",
"@angular2-material/progress-circle": "^2.0.0-alpha.1",
"@angular2-material/radio": "^2.0.0-alpha.1",
"@angular2-material/sidenav": "^2.0.0-alpha.1",
"@angular2-material/toolbar": "^2.0.0-alpha.1",
"angular2": "2.0.0-beta.12",
"core-js": "^2.1.5",
"rxjs": "5.0.0-beta.2",
"zone.js": "0.6.6"
},
It's just a regular RxJS, not some kind of light version. 它只是一个普通的RxJS,而不是某种轻型版本。 Shouldn't it include all methods?
它不应该包括所有方法吗?
If you want to include all methods, use: 如果要包括所有方法,请使用:
import 'rxjs/Rx';
If you want to include only skip()
method, use: 如果只想包含
skip()
方法,请使用:
import 'rxjs/add/operator/skip';
Rx is designed to be modular, so that not all code is loaded into memory. Rx设计为模块化,因此并非所有代码都加载到内存中。
Add 加
import 'rxjs/add/operator/skip';
You can also import all at once using 您也可以使用一次导入所有内容
import 'rxjs/Rx';
but that defeats the purpose of the modularization and unnecessarily bloats your code output size. 但这会破坏模块化的目的,并且会不必要地增加代码输出的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.