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;
}
});
Любые идеи?
Я заменил 'console.log ('перейти к выбранной странице');' с '$ location.path (NEWURL)' но это снова вызывает диалоговое окно, так как это пойман на '$ scope. $ on (" $ locationChangeStart ", confirmLeavePage);' Любые идеи? – Larsen