I am working on a Hybrid app written in Ionic-1 that uses Angular-1 javascript library and HTML-5 to create hybrid apps.
In my code I am connecting to Firebase to fetch some data:
MyCtrl:
angular.module('myctrl.controller', [])
.controller('MyCtrl', function () {
$ionicPlatform.ready(function () {
try {
var userRef = firebase.database().ref().child("users/" + loggedInUser.userName + "/details");
userRef.on('child_added', function(snapshot, prevChildKey) {
var newUser = snapshot.val();
console.log("New user " + JSON.stringify(newUser));
});
}
});
});
Now as I understand that controllers are re-instantiated every time views they are attached to are re-created. However, in my app even if I am outside the view which is attached to this controller, and add a user in firebase, this code gets executed. It confuses me as this code should have been garbage collected once view is replaced by another one. Does it mean that this on() method somehow getting attached to $rooScope?