我正在使用带有angularjs的geofire库。在写出基于地理定位的基本查询时,我注意到发生了一些奇怪的事情。状态更改后,页面显示为空白,查询似乎无法执行。但是,如果我按ctrl + f5,数据显示和查询执行。
我想知道为什么会这样。我在下面提供了我的控制器代码。感谢任何帮助,我一直在尝试很多事情(尝试更新用户的地理位置以强制触发事件,$ timeout等)。
'use strict';
angular
.module('m02-discover')
.controller('DiscoverController', [
'$scope', '$state', 'fbRef', 'fbGeo', '$geofire', 'Discover', '$timeout',
function($scope, $state, fbRef, fbGeo, $geofire, Discover, $timeout) {
var ref = new Firebase(fbRef);
var geoRef = new Firebase(fbRef + 'geofire/');
var $geo = $geofire(geoRef);
$scope.searchResults = [];
var query = $geo.$query({
center: [37.68465, -122.1420265],
radius: 10
});
// Setup Angular Broadcast event for when an object enters our query
var geoQueryCallback = query.on('key_entered', 'SEARCH:KEY_ENTERED');
// Listen for Angular Broadcast
$scope.$on('SEARCH:KEY_ENTERED', function (event, key, location, distance) {
// Do something interesting with object
ref.child('users').child(key).once("value", function(snapshot) {
var user = snapshot.val();
$scope.$apply(function(){
$scope.searchResults.push(user);
});
});
// Cancel the query if the distance is > 50 km
if(distance > 50) {
geoQueryCallback.cancel();
}
});
$scope.favoriteUser = function(favoritedID, favoritedTwitterID){
Discover.favoriteUser(favoritedID, favoritedTwitterID);
}
}
]);