I use durandal and requirejs to create my view models. I also connect to the deactivate lifecycle callback method every time I move from view. I want to get rid of my view model in this method.
I tried delete this , this = undefined , but they don't seem to work.
I also use the durandal event aggregator as follows:
self.activate = () => { App.trigger("testEvent"); }; App.on("testEvent").then(() => { alert('Event Triggered!'); });
Thus, every time a view model is loaded, an event is fired. Now, if I go from the view, then go back (hence, the view model will be loaded again), then the event will fire twice. If I go to view the third time, the event will be fired 3 times, etc. Etc. Thus, previous view modes are still present, so the durandal event is fired by each view model. Therefore, to fix this problem, I need to turn off the view modes when deactivating, how can I do this?
Note. the models in question are temporary, not solitary.
source share