我正在尝试编辑资源并在我的编辑表单上显示用户数据。除了更新之外,我的所有其他CRUD操作都在工作。有人可以帮助我理解并纠正这个错误:
错误:$ resource:badcfg响应与配置的参数
不匹配以下是代码:
form.adults.html
<td><a ui-sref="form.adults-edit()"><button class="btn btn-primary btn-sm">Edit</button></a></td>
app.js
var app = angular.module("LunchApp", ["ngVidBg", "ngAnimate","ui.router",'ngResource']);
app.config(function($stateProvider,$urlRouterProvider) {
$stateProvider
.state('form.adults-edit', {
url: '/adults/{{adult._id}}/edit',
controller: "EditAdultController",
templateUrl: "views/a-edit.html"
})
$urlRouterProvider.otherwise('login');
});
services.js
app.service("AdultService",['$resource', function($resource){
return $resource('/api/adults/:id', {id: '@_id'}, {
update : {
method: 'PUT'
}
});
}]);
controllers.js
app.controller("EditAdultController", function($scope, $location, $stateParams, AdultService){
AdultService.get({id: $stateParams.id},function(adult){
$scope.adult = adult;
console.log(adult);
}, function(err){
$state.go('form.adultsInHousehold1');
});
$scope.editAdult = function(adult){
console.log("This is working!");
$scope.adult.$update(function(){
$state.go('form.adultsInHousehold1');
});
};
});