<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Processing $http.get() response in service</title>
<script src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<script>
var app = angular.module('myServiceApp', []);
app.factory('myfactService', function($http) {
return {
myServices: function() {
return $http.get('api.json'); //this returns promise
}
};
});
app.controller('myServiceCtrl', function(myfactService, $scope) {
$scope.result = null; //default is null
//Call the services
myfactService.myServices().then(function(rest) {
if (rest) {
if (rest.data)
$scope.result = rest.data;
}
});
});
</script>
</head>
<body ng-app="myServiceApp">
<div ng-controller="myServiceCtrl">
Output Reuslt: {{result}}
<br/> Reuslt at 0 index: {{result[0]}}
<br/> Reuslt at 1 index: {{result[1]}}
<br>
</div>
</body>
</html>
// Code goes here
/* Styles go here */
["hello", "Anil"]