我在 RXJS 中读到了这个很棒的功能,理论上它允许我只订阅一个响应,但似乎无法实现它。相反,我收到此错误,
"Property 'first' does not exist on type 'Observable'."
尽管我只是从现有示例中复制粘贴。
这是我的代码:
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
});
};
最佳答案
你需要import 'rxjs/add/operator/first'
;
在您的文件中。
关于angular - 似乎无法在 Observable 上使用 'first()'(Angular 中的 rxjs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46328968/