问题
I read about this awesome feature in RXJS which would theoretically allow me to subscribe only for one response, but can't seem to implement it. Instead, I'm getting this error,
"Property 'first' does not exist on type 'Observable'."
although I am just copy-pasting from existing examples. Here's my code:
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
});
};
回答1:
You need to
import 'rxjs/add/operator/first'
;
in your file.
回答2:
Add import 'rxjs/add/operator/first'
to your component.ts file.
It comes from the import first.
来源:https://stackoverflow.com/questions/46328968/cant-seem-to-use-first-on-observablerxjs-in-angular