A.Shoman
A.Shoman

Reputation: 3085

http get request using angularjs

So I am trying to send Get request with angularjs

However I am getting this error

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

here is my code

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

Upvotes: 0

Views: 1782

Answers (2)

icanbeacoder
icanbeacoder

Reputation: 1388

Instead of

function SimpleController($scope,$http)...

try using

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

// function body

});

Upvotes: 2

lucuma
lucuma

Reputation: 18339

It looks like you have an extra comma causing the invalid function:

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

Upvotes: 0

Related Questions