
Security News
Free Certified Patch for Critical Rails Active Storage Vulnerability
Socket has released a free Certified Patch for a critical Rails Active Storage vulnerability, giving developers time to upgrade to a secure Rails version.
angular-modal
Advanced tools

A modal factory service for AngularJS that makes it easy to add modals to your app.
bower install angular-modal
modal.js script provided by this component into your app.modal.css style provided by this component into your html.btford.modal as a module dependency to your app.app.js
angular.module('myApp', ['btford.modal']).
// let's make a modal called `myModal`
factory('myModal', function (btfModal) {
return btfModal({
controller: 'MyModalCtrl',
controllerAs: 'modal',
templateUrl: 'my-modal.html'
});
}).
// typically you'll inject the modal service into its own
// controller so that the modal can close itself
controller('MyModalCtrl', function (myModal) {
this.closeMe = myModal.deactivate;
}).
controller('MyCtrl', function (myModal) {
this.showModal = myModal.activate;
});
my-modal.html
<div class="btf-modal">
<h3>Hello {{name}}</h3>
<p><a href ng-click="modal.closeMe()">Close Me</a></p>
</div>
index.html
<div ng-app="myApp" ng-controller="MyCtrl as ctrl">
<a href ng-click="ctrl.showModal()">Show the modal</a>
</div>
If you add any listeners within the modal's controller that are outside the modal's scope,
you should remove them with $scope.$on('$destroy', fn () { ... }) to avoid creating a memory leak.
Building on the example above:
app.js
// ...
controller('MyModalCtrl', function (myModal, $timeout) {
var ctrl = this,
timeoutId;
ctrl.tickCount = 5;
ctrl.closeMe = function () {
cancelTick();
myModal.deactivate();
};
function tick() {
timeoutId = $timeout(function() {
ctrl.tickCount -= 1;
if (ctrl.tickCount <= 0) {
ctrl.closeMe();
} else {
tick();
}
}, 1000);
}
function cancelTick() {
$timeout.cancel(timeoutId);
}
$scope.$on('$destroy', cancelTick);
tick();
}).
// ...
Note: The best practice is to use a separate file for the template and a separate declaration for the controller, but inlining these options might be more pragmatic for cases where the template or controller is just a couple lines.
angular.module('myApp', []).
// let's make a modal called myModal
factory('myModal', function (btfModal) {
return btfModal({
controller: function () {
this.name = 'World';
},
controllerAs: 'ctrl',
template: '<div class="btf-modal">Hello {{ctrl.name}}</div>'
});
}).
controller('MyCtrl', function (myModal) {
this.showModal = myModal.activate;
});
<div ng-app="myApp" ng-controller="MyCtrl">
<a href ng-click="ctrl.showModal()">Show the modal</a>
</div>
btfModalThe modal factory. Takes a configuration object as a parameter:
var modalService = btfModal({
/* options */
})
And returns a modalService object that you can use to show/hide the modal (described below).
The config object must either have a template or a templateUrl option.
These options work just like the route configuration in Angular's
$routeProvider.
config.templatestring: HTML string of the template to be used for this modal.
Unless the template is very simple, you should probably use config.templateUrl instead.
config.templateUrlstring (recommended): URL to the HTML template to be used for this modal.
config.controllerstring|function (optional): The name of a controller or a controller function.
config.controllerAsstring (optional, recommended): Makes the controller available on the scope of the modal as the given name.
config.containerDOM Node (optional): DOM node to prepend . Defaults to document.body.
modalServiceA modalService has just two methods: activate and deactivate.
modalService.activateTakes a hash of objects to add to the scope of the modal as locals.
Adds the modal to the DOM by prepending it to the <body>.
Returns a promise that resolves once the modal is active.
modalService.deactivateRemoves the modal (DOM and scope) from the DOM. Returns a promise that resolves once the modal is removed.
modalService.activeReturns whether or not the modal is currently activated.
You can run the tests with karma:
karma start karma.conf.js
MIT
FAQs
easily add a modal to your angular app
The npm package angular-modal receives a total of 111 weekly downloads. As such, angular-modal popularity was classified as not popular.
We found that angular-modal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.

Security News
Socket has released a free Certified Patch for a critical Rails Active Storage vulnerability, giving developers time to upgrade to a secure Rails version.

Security News
/Threat Research
A malicious Ruby gem runs a credential-stealing worm during installation, poisons AI coding tools, and can wipe files when a stolen GitHub token is revoked.

Security News
GitHub is tightening GitHub Actions security with new restrictions on privileged pull request workflows. Here's what changes and how maintainers are affected.