Imagine we are utilizing the pushState to navigate through routes:
$locationProvider.html5Mode(true);
We have two routes with different controllers:
$stateProvider.state('one', {
url:'/one',
templateUrl:'one.html',
controller: 'oneCtrl'
});
$stateProvider.state('two', {
url:'/two',
templateUrl:'two.html',
controller: 'twoCtrl'
});
The oneCtrl
creates a new instance of the same resource as twoCtrl
:
.controller('oneCtrl', ["$scope", "$firebase", function($scope, $firebase) {
var oneRef = new Firebase("https://example.firebaseio.com/stuff");
$scope.stuff = $firebase(oneRef);
$scope.stuff.$on("loaded", function(value) {
console.log(value);
});
}])
.controller('twoCtrl', ["$scope", "$firebase", function($scope, $firebase) {
var twoRef = new Firebase("https://example.firebaseio.com/stuff");
$scope.stuff = $firebase(twoRef);
$scope.stuff.$on("loaded", function(value) {
console.log(value);
});
}])
- When navigating to
/one
, the$on("loaded")
event triggers as expected for theoneRef
. - If we then proceed from
/one
to/two
, the$on("loaded")
event does not trigger.
If a new reference was created - twoRef
- why is the callback not firing a second time?