Subject.onNext is not a function

I am trying to use someactiveiveX in my http code. To do this, I create a theme and try to call the onNext function, but I get an error: subject.onNext is not a function.

html:
<input #search (input)="generateSuggestions($event.target.value)">

c

 import { Jsonp, Response } from 'angular2/http'; import { Observable } from 'rxjs/Observable'; import { Subject } from 'rxjs/Subject' import 'rxjs/add/operator/map'; import 'rxjs/add/operator/debounce'; import { Injectable } from 'angular2/core'; @Injectable() export class SearchService { queryStream = new Subject(); generateSuggestions(query: string) { this.queryStream.onNext(query) .debounce(500) .map( query => this.jsonp.request( `http://urlendpoint/${query}` ) .map( (res: Response) => res.json() ) .subscribe( results => console.log(results) ); ) } } var queryStream = new Subject(); 

ORIGINAL EXCLUSION: TypeError: this.queryStream.onNext is not a function

All my simple http functions work (this.jsonp.request (url / query) .map (). Subscribe ()), but the onNext statement does not work. I also have a problem with importing flatMap, which does not seem to be in the same folder "rxjs / add / operator / ..." as the map and debounce.

+7
angular
source share
1 answer

replace

 import { Observable } from 'rxjs/Observable'; import { Subject } from 'rxjs/Subject' import 'rxjs/add/operator/map'; import 'rxjs/add/operator/debounce'; 

Through:

 import * as Rx from "rxjs/Rx"; 

and

Replace Subject with Rx.Subject

Replace onNext with next

+10
source share

All Articles