I am a beginner in angularjs. Recently, I created an angularJS service based on the following diagram:
https://i.sstatic.net/NifC5.png
The Global Service acts as a way for controllers to communicate with each other. It holds data shared between parent and child controllers. The Grand Parent controller opens a popup dialog which includes parentController2, and that further opens another popup with childController3.
My goal is to ensure that data stored in the global service is set to null when its associated controller is destroyed. Since services are singleton in angularjs, I don't want them to hold variables throughout the entire application lifecycle if they're not needed.
In addition, I'm utilizing the controllerAs syntax and avoiding the use of $scope (I understand that garbage collection can be done in the '$destroy' event on scope) to ensure compatibility with angularjs 2.0.
Is there a way to clean up unnecessary variables in a service from a controller when using the controllerAs syntax?
I apologize for the basic question. Thank you in advance.