4

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
    });
};
Michael
  • 5,910
  • 4
  • 52
  • 74
Efim Rozovsky
  • 181
  • 1
  • 8

2 Answers2

5

You need to

import 'rxjs/add/operator/first';

in your file.

alexKhymenko
  • 4,840
  • 17
  • 36
2

Add import 'rxjs/add/operator/first' to your component.ts file.

It comes from the import first.

Sajeetharan
  • 186,121
  • 54
  • 283
  • 331