我有以下问题:
1-当我的模型打开时,我点击“取消”'关闭它,它重新加载页面。
2-当我点击“确定”时,我的“删除”请求不会发送到服务器(它没有收到任何内容),并重新加载页面。我也没有被重定向到我打算去的页面。
HTML
<div>
<input type="button" class="btn btn-primary" ng-click="suppr()" value="ok"/>
<input type="button" class="btn btn-default" ng-click="annulSupp()" value="cancel" />
</div>
档案js
(function() {
'use strict';
var progress = angular.module('demret.progress', ['ui.bootstrap.modal']);
progress.directive('progressDem', function() {
return {
restrict : 'E',
templateUrl : "progress/progress.html",
controller : [ '$scope', '$http', 'Demande', '$window', '$modal', function($scope, $http, Demande, $window, $modal) {
// TODO
$scope.supprimerDemande = function() {
var urlSetDem = cfg.urlDDRRest + 'demande/' + Demande.get().id;
var config = {
method : 'DELETE',
url : urlSetDem,
jsonExpected : true
};
$http(config).then(function(http) {
$window.location.href = cfg.urlPortail;
})['catch'](function(http) {
$scope.errT= 'Une erreur technique';
})['finally'](function() {
});
}
// ==========================================
// open fenetre modal
// ==========================================
$scope.modalSuppressionDem = function(size) {
// déclaration de la fenetre
var modalInstance = $modal.open({
animation : true,
templateUrl : 'progress/suppression-modal.html',
controller : 'ModalSuppressionDem',
size : size,
backdrop : 'static',
resolve : {
functionSupp : function() {
return $scope.supprimerDemande;
}
}
});
modalInstance.result.then(function() {
// close
});
};
} ]
}
});
// Controleur de la fenetre modale
progress.controller('ModalSuppressionDem', [ '$scope', '$modalInstance', 'functionSupp', function($scope, $modalInstance, functionSupp) {
$scope.suppr = function() {
functionSupp();
$modalInstance.close();
};
$scope.annulSupp = function() {
$modalInstance.close();
};
} ]);
})();
config.js
(function() {
'use strict';
window.cfg = {
urlDDRRest : '/TOTO-rs/api/',
urlPortail : '/TOTO/',
};
})();
有谁知道为什么会这样?
提前谢谢!
答案 0 :(得分:1)
试试这个:
替换
<input type="button" class="btn btn-default" ng-click="annulSupp()" value="cancel" />
带
<input type="button" class="btn btn-default" ng-click="annulSupp($event)" value="cancel" />
并用以下代码替换$ scope.annulSupp()函数
$scope.annulSupp = function(event) {
event.preventDefault();
$modalInstance.close();
};