0
내 컨트롤러에서 내 맵의 위치 변화에 따라 다양한 매개 변수로 URL을 변경했습니다. 이것은 내 setLocation 메소드입니다.
$scope.setLocation = function(lat,lng){
$location.search('lat',lat);
$location.search('lng',lng);
$scope.$apply();
};
다른 방법으로지도에 위치 데이터를로드합니다. 위치가 브라우저의 역사에서 모든 URL의 변경 사항을 저장 변경 시작,하지만 난 뒤로 버튼을 클릭하면 내 컨트롤러의 메소드를 호출하는 방법을 알아낼 수 없습니다되면
$scope.getProjectsByCenter = function(){
var center = getProjectsByCenter();
$scope.setLocation(center.lat(),center.lng());
};
: 이것은 내 getProjectsByCenter입니다. 뒤로 버튼은 $ 위치를 변경하고 다음 브로드 캐스트 리스너가 호출됩니다. 실제로 다음의 브로드 캐스트 리스너는 setLocation()을 호출 할 때마다 호출되지만,이 경우 모든 것이 정상적으로 작동합니다.
app.run(['$rootScope', '$location',
function ($rootScope, $location) {
//Client-side security. Server-side framework MUST add it's
//own security as well since client-based “security” is easily hacked
$rootScope.$on('$locationChangeStart', function (event, next, current) {
if(next !== current && (hasBackButtonBeenClicked() || scopeFunctionWasNotCalled())){
// fetch project again.
// $state.reload();
// $rootScope.$apply(); <--- doesn't work
console.log("location has changed...now find a way to call controller's $scope.getProjectsByCenter()...");
}
});
}]);
의견이 있으십니까?
글쎄, 컨트롤러 자체에이 수신기를 추가 할 수 있는지 알지 못했습니다. tlazocamatli. – webmandman
그것은 그것이하는 것을 가정한다. 그러나 이전과 같은 것이다. 이 콜백 함수는지도 앱이 위치를 변경하고 브라우저가 위치를 변경할 때 호출됩니다. 브라우저 (뒤로 버튼)가 언제 그것을 변경하는지 알 필요가 있습니다. – webmandman
오 오메! 내 getProjects 함수는 위치가 변경 될 때만 호출해야합니다. 내 getProjects를 호출 한 다음 위치를 변경하는 대신 – webmandman