I developed a service that retrieves movie information from the omdb API. However, when I attempt to utilize it in my controller and add the result to my movie array, I encounter an issue.
TypeError: Cannot read property 'push' of undefined
.controller('AppCtrl', function(omdbApi) {
this.movie = [];
this.getMovie = function(title, year) {
year = typeof year === 'undefined' ? "" : year;
omdbApi.getMovie(title, year).then(function(data){
this.movie.push({
poster: data.data.Poster,
title: data.data.Title,
actors: data.data.Actors,
plot: data.data.Plot
});
});
}
});
I am seeking clarification as to why I am encountering difficulty pushing to the movie array. I am uncertain if this is an Angular issue or a JavaScript problem. Based on my testing, the received data appears valid. If I simply assign the data to the movie variable, I find myself unable to access it outside of the function.