AngularJS provides $http control which works as a service to read data from the server. The server makes a database call to get the desired records. AngularJS needs data in JSON format. Once the data is ready, $http can be used to get the data from server in the following manner −
function empController($scope,$http) {
Here, the file data.txt contains employee records. $http service makes an ajax call and sets response to its property employees. employees model can be used to draw tables in HTML.
var url = "data.txt"; $http.get(url).success( function(response) { $scope.employees= response; }); } |