hey guys OMDB APIからムービー情報を取得するためにAngular2のObservablesを使用してライブ検索を実行しようとしています。私はそれがクロムのネットワークタブで動作していることがわかりますが、私はUIで結果を得ることはできません。Observablesを使用してOMDB APIを検索してムービー情報を取得する
@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())
}
}
と私のHTMLコンポーネントで、私は結果を表示するために入力して、UIを持っています。
私はこのように、私のネットワークタブで結果を参照してください入力環境のです
<input [formControl]="search">
<div *ngFor="let movie of movies | async">
<h1>{{movie.title}}</h1>
:
しかし、それはUIに表示されません。誰か助けてもらえますか?ありがとう
はい、テンプレートは100%有効です。 –
あなたは '含めることができます@ Component'デコレータを使用して、コンポーネントに対して 'ChangeDetectionStrategy.OnPush'を使用しているかどうかを確認できますか?そして 'MovieService'はどのように実装されていますか? Angularの 'Http'サービスを使用していますか? – cartant
テンプレートが有効で、その中に閉じた '