Answer the question
In order to leave comments, you need to log in
What is the best way to save service state between angular modules?
There are 2 modules that use the 3rd module. In module 3, there are services that must maintain state over time.
You can stupidly save to the global area (window), but maybe there is an angular-way?
jsfiddle.net/27xo9t5m/1
Answer the question
In order to leave comments, you need to log in
The first time you try to resolve a service somewhere in your application, it is instantiated and lives until the application terminates.
angular.module('my-module', [])
.service('usefulService', function(){
var usefulVar = 0;
this.doSomethingUseful = function(){ userfulVar += 1; return usefulVar; };
this.getUsefulVar = function(){ return usefulVar; }
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question