2
var app = angular.module("mymodule",[]);

app.controller("employeeController",function($scope,$http){
    var url ="data/records.json";

    $http.get(url).success(function(response){
        $scope.employees =response;

    });

});
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396

4 Answers4

3

You should access response.data,also replace success with then,.success has been deprecated.

$http.get(url).then(function(response){
        $scope.employees =response.data;
});
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
1

.success is deprecated since angular version 1.4 To catch the promise you can use then.

Note that response of the then return data inside the data property. so you need to access the data property of that response.

$http.get(url).then(function(response){
        $scope.employees =response.data
});
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80
  • That is inaccurate. The `.success` method was deprecated in version 1.4, removable by configuration in version 1.5, and completely removed in version 1.6. – georgeawg Mar 27 '17 at 17:49
0

Try this way

app.controller("paymentRequestController", ["$scope", "$http", function ($scope, $http) {
        
        $scope.payment_method_info = [];
        $scope.rate = 0;
        $scope.getPaymentInfo = function () {
            $http({
                method: "POST",
                url: url,
            }).success(function (response) {
                if (response.length > 0) {
                    $scope.rate = response[0].rate;
                    $scope.payment_method_info = response;
                } else {
                    $scope.rate = 0;
                    $scope.payment_method_info = [];
                }
            });
        };
      },
    ]);
-1

i don't have enought reputation. i want to add on @Jayanta reply this is another syntax:

.success(function (data, status, headers, config) {
          deffered.resolve(data);

so when you try to add "data" to console.log(data) it will dislay the right data.

Hamdy
  • 430
  • 1
  • 6
  • 19
  • 1
    i am sorry sir, i think you are using the angular version less then 1.6 and the code have some syntax error. the code is traditional way and the success and error method is not working in 1.6 version. – Jayanta Mar 27 '17 at 16:57