Lately, I've been utilizing Angular services to store my commonly used codes that are required across different parts of my project. However, I have encountered an issue where variables in the service are shared between controllers. This means that if one controller modifies a variable, it impacts other controllers as well.
This behavior is not what I desire! I am looking for a solution similar to services but with an isolated environment for each individual controller. Is there any way to achieve this?
UPDATE:
app.service("myService",function(){
this.variable = 1;
});
app.controller("loginCtrl",function($scope,myService){
console.log(myService.variable); //outputs 1
myService.variable++;
});
app.controller("signupCtrl",function($scope,myService){
console.log(myService.variable); //outputs 2
});
I require each controller to use its own instance of myService (isolated from others).