2013-05-13 159 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){

//功能體

});