0

在选择类型以创建对 API 的请求后,我无法尝试附加新的 url 参数。

ng-change的是genreChange。当它被选中时,它应该在提交表单之前自动&with_genre=fiction在url 中附加这样的新 url 参数$scope.moviessubmitButton

<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();
}

我正在使用这种方法,以防用户将其留空。

谢谢

4

1 回答 1

0

这就是 Resource.bind 所做的。

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();
}
于 2013-11-18T01:48:10.750 回答