在我的Angular.js应用程序中,当我通过我的$ resource .query方法发送查询时,查询字符串的字符将作为单独的参数提交。为什么会这样?
结果如下:
cities?0=n&1=e&2=w&3=y&4=o&country_code=US
这是我的代码:
// Cities service used REST endpoint
angular.module('mean.cities').factory("Cities", ['$resource', function($resource) {
return $resource('cities/:query', {
query:'@query',
country_code: 'US'
},
{});
}]);
// Controller Method
$scope.autocompleteCity = function(query) {
Cities.query($scope.query, function(cities) {
console.log(cities);
});
};
// UI Element
<input auto-complete ui-items="names" ng-model="query" class="form-control input-lg" placeholder="Enter A Town" ng-change="autocompleteCity()">
答案 0 :(得分:0)
ngResource
的静态方法期望第一个参数是一个对象。
工作代码:
Cities.query({query: $scope.query}, function(cities) {
// Makes GET request to /cities/washington?country_code=US given the query value of "washington"
console.log(cities);
});