Angular service

Calling service initially

by Rishi Kumar

HTML

<script src="https://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-app="myApp">
<div ng-controller="MyCtrl1">
 {{name}}
</div>
</div>

JavaScript

var app = angular.module('myApp',["initmodule"]);
app.controller("MyCtrl1",function($scope) {
    $scope.name = 'Superhero';
})

angular.module("initmodule",[])
.service("customService", function(){
	this.value = [];
  this.getValue=function(){
  	return this.value;
  }
  this.setValue=function(){
  		console.log("Hello")
      for(i=0;i<10;i++){
    		this.value.push({name:"Rishi"+Math.random().toString(5),age:Math.random().toFixed(2)})
    }
    console.log("Complete")
  }
  this.setValue();
})