[英]How to show a thank you message after someone submits a form in Angular?
我已經在Angular中制作了以下代碼段: http : //plnkr.co/edit/kQz0fiaXLv7T37N8fzJU?p=preview
$scope.loadEditForm = function () {
$scope.checkItem = "yes";
$modal.open({
templateUrl: 'modal.html',
controller: 'modalController',
scope: $scope
})
.result.then(function() {
alert('closed');
});
};
如您所見,我正在提示“關閉”彈出窗口,但我想使其更加時尚並在模式中顯示消息,而不必顯示顯示“關閉”的丑陋彈出屏幕。
如何在Angular中做到這一點? 有一些漂亮的把戲嗎?
您可以擁有服務並定義以下引導程序模態函數。 template =“ url,其中是模態所在的位置”。 並使用showThankYouCtrl顯示消息
$uibModal.open({
animation: true,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
template: template,
size: 'md',
controller: function ($uibModalInstance) {
this.data = "Thank you!";
this.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
this.ok = function () {
$uibModalInstance.dismiss('cancel');
};
},
controllerAs: '$showThankYouCtrl'
});
您可以使用$scope
定義的function
來更新modal's state
的值,然后使用setTimeout
將其關閉。
您可以檢查我更新的Plunker 。
ModalController
angular.module('myModule').controller('modalController', function($scope) {
$scope.state = 'open';
$scope.closeModal = shouldDismiss => {
$scope.state = shouldDismiss ? 'canceled' : 'closed';
setTimeout(() => {
if (shouldDismiss) {
return $scope.$dismiss();
}
$scope.$close();
}, 500);
};
});
您可以更改setTimeout
設置的持續時間,以顯示modal
更長的時間。
主控制器
angular.module('myModule').controller('myController', ["$rootScope", "$scope", "$filter", "$modal", function ($rootScope, $scope, $filter, $modal) {
$scope.checkItem = "";
$scope.loadEditForm = function () {
$scope.checkItem = "yes";
$modal.open({
templateUrl: 'modal.html',
controller: 'modalController',
scope: $scope
}).result.then();
};
}]);
當modal
關閉時,添加.result.then()
會觸發動畫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.