2016-11-09 13 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; 
    } 


}); 

任意のアイデア?

答えて

0

私は `はconsole.log( '選択したページに行く')に置き換え、この

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

     e.preventDefault(); 
     return; 
    } 
+0

を試してみてください。 ' $のlocation.path(NEWURL) ' で' をしかし、それはだから、それは再びダイアログをトリガ '$ scope。$ on(" $ locationChangeStart "、confirmLeavePage); アイデアはありますか? – Larsen

関連する問題