Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

How can I get json data via ajax with angular? I tried a lot but my code is not working. My code:

<!DOCTYPE html>
<html lang="en" ng-app="test">

<head>
  <meta charset="UTF-8">
  <title></title>
  <script src="https://code.angularjs.org/1.6.1/angular.min.js"></script>
  <script>
    angular.module('test', [])
      .controller('TestCtrl', function($scope, $http) {
        $scope.data = [];
        $http.get("http://jsonplaceholder.typicode.com/users").then(function(res) {
          $scope.data = JSON.parse(res);
        });
      });
  </script>
</head>

<body ng-controller="TestCtrl">
  <div ng-repeat="item in data">
    {{item.id}}
  </div>
</body>

</html>
share|improve this question
    
would you please explain what happens with your code? Does it throw an error in the browser console? – marche Jan 17 at 2:25
up vote 0 down vote accepted

Did you try like this..

<script>
        var app = angular.module('test', [])
        app.controller('TestCtrl', function ($scope, $http) {
            $http.get("http://jsonplaceholder.typicode.com/users").then(function(res,status,xhr) {
                $scope.data = res.data;
            });
        });
    </script>
share|improve this answer
    
Thank you very much :) – Enes Giray Jan 17 at 2:46
    
@Enes Giray glad to help you.Best of luck ahead. – Hikmat Sijapati Jan 17 at 3:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.