【发布时间】:2016-01-01 23:52:52
【问题描述】:
我正在玩 https://github.com/Reactive-Extensions/RxJS 尝试使用 Typescript 和 Angular 2 运行他们的示例。当我编译代码时,它抱怨“属性 'pluck' 在类型 'Observable' 上不存在” .我不明白为什么 pluck 不可用。 rxjs 5 是否已将其删除?
使用:
角度 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);
}
}
【问题讨论】:
-
我认为你应该有类似
Observable.fromEvent<TYPE[]>()的东西,其中TYPE是你从该函数中获得的项目类型。 -
快速解决方案是
Observable.fromEvent<any[]>(...) -
@Louy 这无济于事。这不是打字稿问题。问题是 pluck 还没有实现。
标签: angular typescript rxjs