Created
October 14, 2016 12:16
-
-
Save wallacemaxters/f865ad2d53f93b4389679bec04ba0dd8 to your computer and use it in GitHub Desktop.
confirm and alert dialog using uib-modal of the ui angular bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('ui.bootstrap.dialogs', ['ui.bootstrap']) | |
.factory('$dialogConfirm', function ($uibModal) { | |
return function (message, title) { | |
var modal = $uibModal.open({ | |
size: 'sm', | |
template: '<div class="modal-header">\ | |
<h4 class="modal-title" ng-bind="title"></h4>\ | |
</div>\ | |
<div class="modal-body" ng-bind="message"></div>\ | |
<div class="modal-footer">\ | |
<button class="btn btn-default" ng-click="modal.dismiss()">não</button>\ | |
<button class="btn btn-primary" ng-click="modal.close()">sim</button>\ | |
</div>', | |
controller: function ($scope, $uibModalInstance) { | |
$scope.modal = $uibModalInstance; | |
if (angular.isObject(message)) { | |
angular.extend($scope, message); | |
} else { | |
$scope.message = message; | |
$scope.title = angular.isUndefined(title) ? 'Mensagem' : title; | |
} | |
} | |
}); | |
return modal.result; | |
} | |
}) | |
.factory('$dialogAlert', function ($uibModal) { | |
return function (message, title) { | |
var modal = $uibModal.open({ | |
size: 'sm', | |
template: '<div class="modal-header">\ | |
<h4 class="modal-title" ng-bind="title"></h4></div>\ | |
<div class="modal-body" ng-bind="message"></div>\ | |
<div class="modal-footer">\ | |
<button class="btn btn-primary" ng-click="modal.close()">OK</button>\ | |
</div>', | |
controller: function ($scope, $uibModalInstance) { | |
$scope.modal = $uibModalInstance; | |
if (angular.isObject(message)) { | |
angular.extend($scope, message); | |
} else { | |
$scope.message = message; | |
$scope.title = angular.isUndefined(title) ? 'Mensagem' : title; | |
} | |
} | |
}); | |
return modal.result; | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example