myApp = angular.module('Modaldemo', ['ui.bootstrap']);
myApp.controller('ModalDemoCtrl',['$scope','$uibModal','$log','$document', function ($scope, $uibModal, $log, $document) {
$scope.items = ['item1', 'item2', 'item3'];
$scope.animationsEnabled = true;
$scope.open = function (size, parentSelector) {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
backdrop: true,
templateUrl: 'myModalContent.html',
keyboard: true,
controller: 'ModalInstanceCtrl',
size: size,
appendTo: angular.element(document.getElementsByTagName('body')[0]),
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
console.log('selectedItem-->',selectedItem);
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
$scope.openComponentModal = function () {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
component: 'modalComponent',
resolve: {
items: function () {
return $scope.items;
}
}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('modal-component dismissed at: ' + new Date());
});
};
$scope.openMultipleModals = function () {
$uibModal.open({
animation: $scope.animationsEnabled,
ariaLabelledBy: 'modal-title-bottom',
ariaDescribedBy: 'modal-body-bottom',
templateUrl: 'stackedModal.html',
size: 'sm',
controller: function($scope) {
$scope.name = 'bottom';
}
});
$uibModal.open({
animation: $scope.animationsEnabled,
ariaLabelledBy: 'modal-title-top',
ariaDescribedBy: 'modal-body-top',
templateUrl: 'stackedModal.html',
size: 'sm',
controller: function($scope) {
$scope.name = 'top';
}
});
};
$scope.toggleAnimation = function () {
$scope.animationsEnabled = !$scope.animationsEnabled;
};
}]);
myApp.controller('ModalInstanceCtrl',['$scope','$uibModalInstance','items', function ($scope, $uibModalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function () {
console.log('ok functon');
$uibModalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
console.log('cancel functon');
$uibModalInstance.dismiss('cancel');
};
}]);