我已经检查了有关错误的其他解决方案错误:[ng:areq],大多数都说明了丢失文件功能,复制变量或覆盖模块的原因。我的controller.js代码如下所示,它似乎没有任何问题。
var app = angular.module('app', ['ngRoute']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.otherwise({redirectTo: '/home'});
$routeProvider.when('/home', {
templateUrl: 'home.html',
controller:'ServiceController'
});
$routeProvider.when('/servicess/:id', {
templateUrl: 'services.html',
controller: 'ServicesController'
});
}]);
app.controller('ServiceController', function($scope,$http){
$scope.description='Users Details';
$scope.add = function(){
$http.post('/users', $scope.user)
.success($scope.people);
};
$scope.people = function(){
$http.get('/users')
.success($scope.renderUser);
};
$scope.renderUser = function(response){
$scope.users = response;
};
$scope.remove = function(id){
$http.delete('/users/'+id).success($scope.people);
};
$scope.people();
});
app.controller('ServicesController', function($scope,$http,$routeParams,$location){
$http.get('/servicess/'+$routeParams.id)
.success(function(data) {
$scope.personal=data;
});
$scope.update = function(id){
$http.put('/servicess/'+id,$scope.personal)
.success(console.log('Error: [ng:areq]'));
};
});
错误总是在成功回调
中的$ scope.update函数期间出现$scope.update = function(id){
$http.put('/servicess/'+id,$scope.personal)
.success(console.log('Error: [ng:areq]'));
};
如果成功回调为空,则不会出现错误。我在这里做错了什么或者缺少一些语法或陈述吗?
答案 0 :(得分:1)
根据要求,我将其作为答案发布
您将console.log
作为参数传递给success
,而不是这样做
$scope.update = function(id){
$http.put('/servicess/'+id,$scope.personal)
.success(function() {
console.log("PUT successful");
});
};