angularjs service example
HTML
<div ng-app="MyApp">
<div ng-controller="MyCtrl">
{{data1}}
<br />
{{data2}}
<br />
{{data3}}
</div>
</div>
JavaScript
var app = angular.module('MyApp', [])
app.service('Service1', function(){
return {
ajxResponse1: 'dataFromService1'
};
});
app.service('Service2', function(){
return {
ajxResponse2: 'dataFromService2'
};
});
app.service('Service3', function(){
return {
ajxResponse3: 'dataFromService3'
};
});
function MyCtrl($scope, Service1, Service2, Service3){
alert('Entering MyCtrl');
$scope.data1 = Service1.ajxResponse1;
$scope.data2 = Service2.ajxResponse2;
$scope.data3 = Service3.ajxResponse3;
alert('Exiting MyCtrl');
}