Angularjs $http.get does not work

emredmrl picture emredmrl · Apr 26, 2015 · Viewed 20.7k times · Source

My purpose is to consume a REST web service in AngularJS and I am making some trials right now. Below code is not working and throwing following exception. Can you help me identifty the problem?

Thanks in advance.

function getUsersFromLocal($scope,$http)
{
 $http.get('http://localhost:8080/people').
 success(function(data) {
 $scope.data = data;
 });
return data;
}

Error is: TypeError: Cannot read property 'get' of undefined at getUsersFromLocal.

The service is accessible and I tested it through some REST clients.

Answer

sparsh610 picture sparsh610 · Apr 26, 2015

Try like this , this way i found on w3school.

var app = angular.module('myApp4', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("http://www.w3schools.com/angular/customers.php")
                .success(function(response) {
                    $scope.data= response.records;
                });
    });