似乎无法在 Observable 上使用“first()”(Angular 中的 rxjs)

Efi*_*sky 4 subscribe rxjs angular

我在 RXJS 中读到了这个很棒的功能,理论上它允许我只订阅一个响应,但似乎无法实现它。相反,我收到此错误,

“'Observable' 类型不存在属性 'first'。”

尽管我只是从现有示例中复制粘贴。这是我的代码:

implementHash( token ){
    console.log('trying to implement hash', token);
    const req = this.http.get('http://localhost:3003/token/' + token );
    const sub = req
        //.first()
        .subscribe( res =>{
            sub.unsubscribe; // trying to avoid this line
    });
};
Run Code Online (Sandbox Code Playgroud)

ale*_*nko 5

你需要

import 'rxjs/add/operator/first';

在您的文件中。