I am working on a movie database, I am using the MovieDb api. I currently have 20 random generated movies without an user input, so I know the api is working.
I have my HTML with an input to take in the movie name and a button to activate the method:
<button id="searchBarButton" (click)="sendRequest(MovieTitle)">Search</button>
<input id="MovieTitle" class= "searchBar" type="text" #MovieTitle>
The in my .ts for the search component.I am setting up the subscription to my service which will allow me to use the API and search through it:
sendRequest(value)
{
// Need to route the shit outta this
this._iMDBService.searchMDBMovie(this.MovieTitle).subscribe( shows => {
this.searchedShows=shows.results;
this.router.navigateByUrl("/details");
},
error=>this.errorMessage=<any>error);
}
As you can see I am trying to send the movie title taken in from the user on the HTML and send it to the service below with the .ts file
@Injectable()
export class iMDBService {
private _iMDBURL: string = 'https://api.themoviedb.org/3/';
constructor(private _http: HttpClient) { }
searchMDBMovie(MovieTitle) : Observable<any>{
return this._http.get<any>(this._iMDBURL + 'search/movie?api_key=MyWorkingApiKey&language=en-US&query=' + MovieTitle + '&page=1&include_adult=false')
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
private handleError(err: HttpErrorResponse) {
console.log(err.message);
return Observable.throw(err.message);
}
}
My question: The api is working however I need the movie title in between the api request, the HTML and .ts is not sending to the service.ts, how do I bring the titlename to the service.ts file?