0

I am having trouble trying to append a new url parameter after selecting a genre to create a request to the API.

My ng-change is genreChange. When it been selected, it should automatically append the new url parameter like this &with_genre=fiction in the $scope.movies url before submitting the form with submitButton

<form ng-submit="submitButton()" name="cForm" class="form-horizontal">
    <h2>Discover the gems</h2>       
        <div class="form-group">
            <select class="form-control" ng-model="genreSelect" ng-change="genreChange()">
                <option ng-repeat="genre in genreList.genres" value="{{genre.id}}">{{genre.name}}</option>
             </select>    
        </div>

        <input type="submit" value="hello" />           
</form>

-

$scope.genreChange = function() {
    $scope.genreVar =  $scope.genreSelect;
    $scope.movies.get({with_genres: $scope.genreVar});
}

$scope.movies = $resource('http://api.themoviedb.org/3/discover/movie:action', {
    api_key: apikey,
    callback: 'JSON_CALLBACK'
}, {
    get: {
        method: 'JSONP'
    }
});

$scope.submitButton = function() {
    $scope.films = $scope.movies.get();
}

I am doing this method just in case a user leaves it blank.

Thanks

Dimitri Kouvdis
  • 121
  • 1
  • 1
  • 9

1 Answers1

0

This is what Resource.bind does.

var MovieResource = $resource('http://api.themoviedb.org/3/discover/movie:action', {
    api_key: apikey,
    callback: 'JSON_CALLBACK'
}, {
    get: {
        method: 'JSONP'
    }
});

$scope.movies = MovieResource;

$scope.genreChange = function() {
    $scope.genreVar =  $scope.genreSelect;
    $scope.movies = MovieResource.bind({with_genres: $scope.genreVar})
}

$scope.submitButton = function() {
    $scope.films = $scope.movies.get();
}
Kevin Stone
  • 8,831
  • 41
  • 29