This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Modal Directive
Adam A.G. Shamblin edited this page Sep 20, 2016
·
6 revisions
The modal directive provides a reusable base for the creation of further modal dialogs.
The modal directive must be applied as an attribute. Any content within the modal element will be transcluded into the modal.
<a ng-click="openModal()">Open Modal</a>
<div modal="myModal">
<h2>My Modal's Header</h2>
<p>My modal content.</p>
</div>
Then in your controller, add a method to open the modal, referencing the modal's name.
angular.module('ModalDemo', ['ModalModule'])
.controller(['$scope', 'ModalService', function ($scope, ModalService) {
$scope.openModal = function () {
ModalService.openModal('myModal');
};
}]);
Param | Type | Details |
---|---|---|
modal | String | The name of the modal. This must be unique across a page. |
The modal directive fires two events, one when opening and one when closing. The modal:open
and modal:close
events are fired with the name of the modal as an argument.
$scope.$on('modal:open', function (event, name) {
console.log('my modal name is ', name);
});