Hey everyone, I'm currently working on implementing a live search feature using Observables in Angular2 to fetch Movie data from the OMDB API. While I can see that it is functioning correctly in the Chrome Network tab, the results aren't showing up in the user interface.
@Component({
selector: 'movie-card',
templateUrl: './card.component.html'
})
export class Component implements OnInit{
movies: Observable<Array<Movie>>;
search = new FormControl;
constructor(private service: MovieService) {}
ngOnInit(){
this.movies = this.search.valueChanges
.debounceTime(400)
.distinctUntilChanged()
.switchMap(search => this.service.get(search))
}
}
MovieService
@Injectable()
export class MovieService {
constructor (private http: Http) { }
get(path: string){
return this.http
.get('www.omdbapi.com/?s=' + path)
.map((res) => res.json())
}
}
In my HTML Component, I have an input field and the UI section to display the results.
<input [formControl]="search">
<div *ngFor="let movie of movies | async">
<h1>{{movie.title}}</h1>
Even though I can see the results in the Network Tab while typing:
https://i.sstatic.net/Zwwle.png
The UI doesn't update with the results. Any assistance would be greatly appreciated. Thank you!