gpt4 book ai didi

javascript - Angular 错误: [ng:areq]

转载 作者:行者123 更新时间:2023-12-03 09:39:14 27 4
gpt4 key购买 nike

我已经检查了有关错误 Error: [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]'));
};

如果成功回调为空,则不会出现错误。我在这里做错了什么或者遗漏了一些语法或语句吗?

最佳答案

根据要求,我将其作为答案发布

您将 console.log 作为参数传递给 success,而是执行此操作

$scope.update = function(id){
$http.put('/servicess/'+id,$scope.personal)
.success(function() {
console.log("PUT successful");
});
};

关于javascript - Angular 错误: [ng:areq],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31236598/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com