-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposter-widget.component.ts
More file actions
49 lines (42 loc) · 1.16 KB
/
poster-widget.component.ts
File metadata and controls
49 lines (42 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Component, OnInit, Injectable, Input, SimpleChange, OnChanges, SimpleChanges } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class PosterService {
// UPDATE OMDB API_KEY here
apiKey = ``;
movieApiUrl = `https://www.omdbapi.com/?apikey=${this.apiKey}&t=`;
constructor(private http: HttpClient){
}
getPoster(name: string){
return this.http.get(`${this.movieApiUrl}${name}`);
}
}
@Component({
selector: 'app-poster-widget',
templateUrl: './poster-widget.component.html',
styleUrls: ['./poster-widget.component.css']
})
export class PosterWidgetComponent implements OnInit, OnChanges {
constructor(private mvInfoService: PosterService) { }
@Input()
title: string;
public result;
loadPoster():void {
this.mvInfoService.getPoster(this.title).subscribe((data)=>{
if(data['Error']){
this.title = undefined;
this.loadPoster();
}
this.result = data['Poster'];
})
}
ngOnInit(): void {
this.loadPoster()
}
ngOnChanges(changes: SimpleChanges): void {
console.log(JSON.stringify(changes));
this.loadPoster();
}
}