tri_inn

tri_inn

  • NA
  • 1.2k
  • 233.5k

AngularJS: service and factory is singleton ?

Jun 12 2017 10:36 AM
How could i prove with a sample code that angular service and factory is singleton
  1. angular.module('myApp').service('helloService',function($timeout){  
  2.   this.sayHello=function(name){  
  3.     $timeout(function(){  
  4.       alert('Hello '+name);  
  5.     },2000);  
  6.   }  
  7. });  
  8.   
  9. angular.module('myApp').controller('TestController',  
  10.   function(helloService){  
  11.   helloService.sayHello('AngularJS'); // Alerts Hello AngularJS  
  12. }); 
 so please come with a example code which tell me when i will run that angular service and factory is singleton. thanks

Answers (3)