My application has two execution paths.
Root
|
|---Tool1 --> T1Page 1
| --> T1Page 2
|
|---Tool2 --> T2Page 1
| --> T2Page 2
|
|----Factory (F)
Here T1Page2 and and T2Page2 are having similar UI elements and I have defined a factory for that. Now the problem is, if user first start Tool1 and then navigate to Tool2, in T2Page2 it displays the values selected in T1Page2 . This is obviously because of the singleton injection in the controller. How can i make sure that Angular returns a new factory object when user comes to T2Page2.
One solution I can think of is to add a clean up method in the factory and call it whenever user starts the T2Page2. But that doesnt sounds good to me.
Factory
(function () {
var serviceId = 'setUp';
angular.module('app').factory(serviceId , ['common', 'datacontext']);
function setUp(common,datacontext){
var vm = this;
vm.name='';
vm.address='';
return init();
function init() {
return vm;
}
}
}());
T1Page2 Controller 1
(function () {
var controllerId = 'T1Page2';
angular.module('app').controller(controllerId, ['common', 'datacontext', 'setUp', T1Page2]);
function T1Page2(common, datacontext, setup) {
//code omitted
}
}());
T2Page2 Controller 2
(function () {
var controllerId = 'T2Page2';
angular.module('app').controller(controllerId, ['common', 'datacontext', 'setUp', T2Page2]);
function T2Page2(common, datacontext, setup) {
//need a new setUp object here.
// rest of the code omitted
}
}());