我试图使用$ js来获取一个对象数组的ajax调用。我传递一个路径变量,它是对象的id,当我尝试在$ resource上调用查询时,它显示下面给出了错误。资源和控制器代码如下。 我在后端使用Spring MVC,下面给出了Spring代码的其余控制器。请给出一些建议,我在这里做错了什么,最佳做法是什么? 这是控制台中的错误 -
TypeError: V is not a function
at https://cdnjs.cloudflare.com/ajax/libs/angular-resource/1.6.1/angular-resource.min.js:13:165
at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:7:427)
at C.setUrlParams (https://cdnjs.cloudflare.com/ajax/libs/angular-resource/1.6.1/angular-resource.min.js:13:50)
at Function.l.(anonymous function) [as query] (https://cdnjs.cloudflare.com/ajax/libs/angular-resource/1.6.1/angular-resource.min.js:10:156)
at Object.getSubCategoryIdNameFn [as getSubCategoryIdName] (http://localhost:8080/MyCoupon/resources/js/category/category_service.js:17:71)
at r.$scope.catChanged (http://localhost:8080/MyCoupon/resources/js/coupon/coupon_controller.js:13:19)
at fn (eval at compile (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:213:110), <anonymous>:4:221)
at r.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:133:313)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:252:529
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js:264:447
这是我的服务和控制器代码 -
function getSubCategoryIdNameFn(catId){
var deferred = $q.defer();
$resource("admin/rest/subcategory-id-name/:catId",{catId:"@catId"}).query({catId:catId})
.$promise
.then(function(response){
deferred.resolve(response);
},function(error){
deferred.reject(error);
});
return deferred.promise;
}
控制器 -
$scope.catChanged = function (){
categoryService.getSubCategoryIdName($scope.coupon.category).then(function(response){
$scope.subcatList = response;
},function(error){
});
}
我是棱角分明的新手,所以不知道控制台错误说的是什么? 服务器端控制器在春天 -
@RequestMapping(value="subcategory-id-name/{catId}", method=RequestMethod.GET,produces={"application/json"})
public List<SubCategory> getSubCategoryIdAndName(@PathVariable int catId){
return subCategoryService.getSubCategoryIdName(catId);
}