Reputation: 1586
Hie guys i am trying to implement search feature using angular2 http request with the help of this link http://blog.thoughtram.io/angular/2016/01/06/taking-advantage-of-observables-in-angular2.html ....In this example the response from wiki will be an array of string so the code will be like this...
@Component({
selector: 'my-app',
template: `
<div>
<h2>Wikipedia Search</h2>
<input type="text" [ngFormControl]="term"/>
<ul>
<li *ngFor="#item of items | async"></li>
</ul>
</div>
`
})
export class App {
items: Observable<Array<string>>;
term = new Control();
constructor(private wikipediaService: WikipediaService) {
this.items = wikipediaService.search(this.term.valueChanges);
}
}
If the response is an array of objects then i am changing this statement from
items: Observable<Array<string>>; to items: Observable<Array<object>>;
but i am not getting it...somebody please show me a way to implement if the response from remote server is an array of object ... Here is my demo http://plnkr.co/edit/BE3l7lQpic9rzDZyomhP?p=preview Assuming the response is array of objects please guide me
Upvotes: 0
Views: 479
Reputation: 202196
You forgot to include the operators you use. You can add this in your imports:
import {Injectable} from 'angular2/core';
import {URLSearchParams, Jsonp} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/debounceTime'; // <----
@Injectable()
export class WikipediaService {
(...)
}
See this plunkr: http://plnkr.co/edit/ybShAY1hOLoGG2WHlHTW?p=preview.
Upvotes: 2