I have the following code
if (testNavigation() && $scope.selections.somethingChanged) {
return false;
}
in testNavigation I call a modal dialog, and if I answer Ok in this dialog box, I set somethingChanged to false again. My problem is that when the code is executed, the testNavigation dialog and modal traversal are also executed later, and therefore my test does not work, since I need it to work. What should I change for my logic to work correctly, for example. first call my modal dialog and act accordingly in the main function?
This is my testNavigation method:
var testNavigation = function()
{
if ($scope.selections.somethingChanged) {
var modal = $modal.open({
controller: function ($scope) {
$scope.okClass = 'btn-primary',
$scope.okLabel = resourceFactory.getResource('Labels', 'yes'),
$scope.cancelLabel = resourceFactory.getResource('Labels', 'cancel'),
$scope.title = resourceFactory.getResource('Labels', 'unsavedChanges'),
$scope.message = resourceFactory.getResource('Messages', 'unsavedChanges');
},
templateUrl: '/app/templates/modal'
});
modal.result.then(function () {
$scope.selections.somethingChanged = false;
});
}
return true;
}
Run codeHide resultI will try to add more information. I have LoadView () and New () functions in the index page controller. In both of these functions, I need to do the following:
if $scope.selections.somethingChanged = false .
if $scope.selections.somethingChanged = true , . "", .
, testNavigation. , , , . AngularJS/JavaScript, , , . $q, .