2013-05-13 224 views
0

所以我想送Get requestangularjs使用HTTP GET请求angularjs

但是我得到这个错误

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}]; 
    }); 
} 
+0

请张贴''为好,甚至更好http://jsfiddle.net – 2013-05-13 12:44:08

+0

@阿卜杜勒 - 拉赫曼Shoman,我注意到你问4个问题,并没有获得一个答案给任何人。你应该通过点击最好回答你的问题旁边的复选标记来给出答案,以便将来的访问者得到帮助。 – lucuma 2013-05-13 16:33:03

回答

0

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

$http({ 
    url: "http://localhost:8080/petstore/pets/list", 
    method: "GET", // <--- remove that comma 
}) 
+0

好是你是正确的 但它不会作出这样的区别,仍然没有工作 – 2013-05-13 19:29:49

+0

如果您收到一个未定义的错误那是因为你有一些语法问题。你有没有通过jslint运行你的代码? – lucuma 2013-05-13 19:31:19

2

而不是

功能SimpleController($范围,$ HTTP)...

尝试使用

module.controller( 'SimpleController',函数($范围,$ http){

//功能体

});