在 Rx.observable 上找不到采摘
pluck not found on Rx.observable
我正在尝试 https://github.com/Reactive-Extensions/RxJS 尝试 运行 通过他们使用 Typescript 和 Angular 的示例 2. 当我编译代码时它抱怨 "Property 'pluck' does not exist on type 'Observable<{}>'"。我不明白为什么 pluck 不可用。它是否已从 rxjs 5 中删除?
使用:
angular 2.0.0-beta.0
rxjs 5.0.0-beta.0
代码:
import {Component} from 'angular2/core';
import {FORM_DIRECTIVES} from 'angular2/common';
import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import {Title} from '../providers/title';
@Component({
selector: 'home',
directives: [...FORM_DIRECTIVES],
providers: [Title],
pipes: [],
styles: [require('./home.css')],
template: require('./home.html')
})
export class Home {
wikisearch: any = {};
// TypeScript public modifiers
constructor(public title: Title, public http: Http) {
var input = document.getElementById('wikisearch');
/* Only get the value from each key up */
var keyups = Observable.fromEvent(input, 'keyup')
.pluck('target', 'value')
.filter((text) => text.length > 2);
}
}
Angular 2 使用 RxJS 5(https://github.com/ReactiveX/RxJS), which is a complete rewrite of the current version (https://github.com/Reactive-Extensions/RxJS). RxJS 5 is still in beta. Some operators from RxJS 4 are not yet available in RxJS 5. This is the case for pluck
. I recommend you take a look at RxJS 5 documentation and also the migration guide 因为这两个版本之间存在一些 API 差异。
对于此特定示例,您可以使用 map
轻松替换 pluck
运算符:
var keyups = Observable.fromEvent(input, 'keyup')
.map((target) => target.value)
.filter((text) => text.length > 2);
更新: pluck
是 now available in RxJS 5 since version 5.0.0-beta.1.
我正在尝试 https://github.com/Reactive-Extensions/RxJS 尝试 运行 通过他们使用 Typescript 和 Angular 的示例 2. 当我编译代码时它抱怨 "Property 'pluck' does not exist on type 'Observable<{}>'"。我不明白为什么 pluck 不可用。它是否已从 rxjs 5 中删除?
使用:
angular 2.0.0-beta.0 rxjs 5.0.0-beta.0
代码:
import {Component} from 'angular2/core';
import {FORM_DIRECTIVES} from 'angular2/common';
import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import {Title} from '../providers/title';
@Component({
selector: 'home',
directives: [...FORM_DIRECTIVES],
providers: [Title],
pipes: [],
styles: [require('./home.css')],
template: require('./home.html')
})
export class Home {
wikisearch: any = {};
// TypeScript public modifiers
constructor(public title: Title, public http: Http) {
var input = document.getElementById('wikisearch');
/* Only get the value from each key up */
var keyups = Observable.fromEvent(input, 'keyup')
.pluck('target', 'value')
.filter((text) => text.length > 2);
}
}
Angular 2 使用 RxJS 5(https://github.com/ReactiveX/RxJS), which is a complete rewrite of the current version (https://github.com/Reactive-Extensions/RxJS). RxJS 5 is still in beta. Some operators from RxJS 4 are not yet available in RxJS 5. This is the case for pluck
. I recommend you take a look at RxJS 5 documentation and also the migration guide 因为这两个版本之间存在一些 API 差异。
对于此特定示例,您可以使用 map
轻松替换 pluck
运算符:
var keyups = Observable.fromEvent(input, 'keyup')
.map((target) => target.value)
.filter((text) => text.length > 2);
更新: pluck
是 now available in RxJS 5 since version 5.0.0-beta.1.