Javascript 从视图调用控制器方法时出错-AngularJS
从视图调用控制器方法getListCategories()时出现此错误 TypeError:在非对象上调用Object.keys at Function.keys(本机) 延伸时(app/bower_components/angular/angular.js:412:25) 位于Function.angular.module.provider.$get.Resource.(匿名函数)(app/bower_components/angular Resource/angular Resource.js:575:15) 位于Scope.$Scope.getListCategories(app/shoppinglist/shoppinglist.js:17:69) at$parseFunctionCall(app/bower\u components/angular/angular.js:12332:18) 在Object.expressionInputWatch(app/bower_components/angular/angular.js:12735:31) 范围$get.Scope.$digest(app/bower_components/angular/angular.js:14217:40) 范围$get.Scope.$apply(app/bower_components/angular/angular.js:14488:24) 完成时(app/bower_components/angular/angular.js:9646:47) 在完成任务时(app/bower_components/angular/angular.js:9836:7)(22:31:11:425 | error) 我不确定这是否是最好的方法,所以任何建议都是非常受欢迎的 服务Javascript 从视图调用控制器方法时出错-AngularJS,javascript,json,angularjs,Javascript,Json,Angularjs,从视图调用控制器方法getListCategories()时出现此错误 TypeError:在非对象上调用Object.keys at Function.keys(本机) 延伸时(app/bower_components/angular/angular.js:412:25) 位于Function.angular.module.provider.$get.Resource.(匿名函数)(app/bower_components/angular Resource/angular Resource.j
shoppingListService.factory('ShoppingLists', function ($resource) {
var factory = {
getShoppingLists: $resource('http://localhost:8080/ShoppingListBackend/webresources/shoppinglists', {}, {
all: {method: 'GET', isArray: true}
}),
getCategories : $resource('http://localhost:8080/ShoppingListBackend/webresources/shoppinglists/getcategories/:id', {id: '@id'}, {
byId: {method: 'GET', isArray: true}
})
};
return factory; });
控制器
.controller('ShoppingListController', function ($scope, ShoppingLists) {
$scope.shoppinglists = ShoppingLists.getShoppingLists.all();
$scope.getListCategories = function (id) {
$scope.listCategories = ShoppingLists.getCategories.byId(id);
};
});
查看
<div id="card" ng-controller="ShoppingListController" ng-repeat="list in shoppinglists">
<div id="card_title">{{list.title}}</div>
<div id="card_subtitle"><span>{{getListCategories(list.id)}}</span></div>
<div id="card_body">
<input type="checkbox" id="item_checked">
<label for="item_checked">Toilet Paper</label>
</div>
{{list.title}
{{getListCategories(list.id)}
厕纸
服务器控制台上会发生什么?什么是响应代码?Jigar Joshi,我不明白你的问题,你说的响应代码是什么意思?@JigarJoshi我怎么看HTTP响应代码?该视图显示的是“{getListCategories(list.id)}}”,而不是方法结果。请使用浏览器发出GET请求,然后查看对RESTful服务的GET请求。