假设我们正在使用推送状态导航路线:
$locationProvider.html5Mode(true);
有两条路线有两个不同的控制器:
$stateProvider.state('one', {
url:'/one',
templateUrl:'one.html',
controller: 'oneCtrl'
});
$stateProvider.state('two', {
url:'/two',
templateUrl:'two.html',
controller: 'twoCtrl'
});
oneCtrl
创建对同一资源的新引用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);
});
}])
- 如果我们导航到
/one
the $on("loaded")
事件按预期触发 - 独一无二oneRef
.
- 如果我们然后从
/one
to /two
the $on("loaded")
事件不会触发。
如果实例化了一个新的引用 -twoRef
- 为什么回调不触发第二次?