Get User Details using $http
Table of Content:
- 1. Get User Details using $http
- Write an AngularJS program to read JSON data from: https://jsonplaceholder.typicode.com/users
- Define the empty scope variable users, and assign the response JSON to the scope variable users. Display the user ID and email of all users in a table format.
Sample Code
index.jsindex.htmlvar app = angular.module('myApp', []); app.controller('myCtrl', function ($scope, $http) { //Define scope variable users here //Use http service that consumes https://jsonplaceholder.typicode.com/users });
User Name Email ID {{user.name}} {{user.email}}
Solution
index.jsvar app = angular.module('myApp', []); app.controller('myCtrl', function($scope, $http) { $scope.users = []; $http.get("https://jsonplaceholder.typicode.com/users") .then(function(response) { $scope.users = response.data; }); });