0

所以我试图Get requestangularjs发送

但是我收到了这个错误

Error: Argument 'SimpleController' is not a function, got undefined

这是我的代码

var module = angular.module('myApp', []);

module.config(function ($httpProvider) {
    $httpProvider.defaults.headers.post['SOAPAction'] = 'http://schemas.microsoft.com/sharepoint/soap/UpdateListItems';
});

function SimpleController($scope,$http)
{
    $http({
        url: "http://localhost:8080/petstore/pets/list",
        method: "GET",
    })
    .success(function(data){
        console.log("SUCCESS");
        $scope.pets = data;
    }).error(function() {
        console.log("FAIL");
        console.log("data: "+data+"\nstatus: "+status+"\nheaders: "+headers+"\nconfig: "+config)
        $scope.pets = [ {"id":1,"name":"Angelfish","description":"Saltwater fish from Australia","category":"Fish","imageUrl":"fish1.jpg","price":10}];
    });
}
4

2 回答 2

2

代替

函数 SimpleController($scope,$http)...

尝试使用

module.controller('SimpleController',function($scope,$http){

// 函数体

});

于 2013-11-13T17:35:39.017 回答
0

看起来您有一个额外的逗号导致无效功能:

$http({
    url: "http://localhost:8080/petstore/pets/list",
    method: "GET",  // <--- remove that comma
})
于 2013-05-13T13:14:10.643 回答