2016-11-09 2 views
0

특정 조건이 충족되면 페이지를 떠날 것을 사용자가 확인해야합니다. 문제는 위치 변경이 대화 상자에서 사용자 응답을 기다리는 것이 아니라는 것입니다.대화 상자에서 사용자 응답을 기다리지 않는 이벤트

각 모듈 1 :

... 
function confirmLeavePage(e, newUrl) { 
     if(form.cod.value) { 
      customDialog.confirmDialog('Title','Leave?').then(
      function(){ 
       console.log('go to selected page'); 
      },function(){ 
       e.preventDefault(); 
      }); 
     } 
    } 

    $scope.$on("$locationChangeStart", confirmLeavePage); 
... 

각 모듈 2 :

angular.module('dialog').service('customDialog', function($mdDialog, $q, $location) { 

    this.confirmDialog = function(title, content){ 
     var deferred = $q.defer(); 
     $mdDialog.show($mdDialog.confirm({ 
      templateUrl:'confirmDialog.html', 
      title : title, 
      textContent : content, 
      ok : 'Confirm', 
      cancel: 'Cancel' 
     })).then(function() { 
      console.log('confirmed'); 
      deferred.resolve(); 
     }, function() { 
      console.log('abort'); 
      deferred.reject(); 
     }); 
     return deferred.promise; 
    } 


}); 

어떤 아이디어

여기 내 코드입니까? `$의 location.path (NEWURL)` 와` 하지만 이후는 다시 대화를 트리거;

답변

0

는 ('선택 페이지로 이동')이

function confirmLeavePage(e, newUrl) { 
     if(form.cod.value) { 
      customDialog.confirmDialog('Title','Leave?').then(
      function(){ 
       console.log('go to selected page'); 
      }); 
     } 

     e.preventDefault(); 
     return; 
    } 
+0

내가 대체 'CONSOLE.LOG 시도 $ scope ($ locationChangeStart, confirmLeavePage); 에 의해 걸렸습니다.; 아이디어가 있습니까? – Larsen

관련 문제