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;

    });

});
5
  • 1
    So what doesnt work? Are there errors in the console? Commented Mar 27, 2017 at 16:00
  • .success has been deprecated.. and do use response.data Commented Mar 27, 2017 at 16:01
  • What is the output of response? (i.e. console.log(response);) Commented Mar 27, 2017 at 16:01
  • Thanks. its working Commented Mar 27, 2017 at 16:04
  • @KhairulIslamTonmoy you checked the answer? Commented Mar 27, 2017 at 16:33

4 Answers 4

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;
});
Sign up to request clarification or add additional context in comments.

1 Comment

You should also be using .then() instead of .success()
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
});

1 Comment

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.
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 = [];
                }
            });
        };
      },
    ]);

Comments

-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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.