confirm-click
v0.7.0
Published
Angular directive for simple href or ng-click confirmation before proceeding
Downloads
13
Maintainers
Readme
confirm-click
Angular directive for simple href or ng-click confirmation before proceeding
<a href="http://github.com" confirm-click="Go to github?">github.com</a>
Install and use
npm install confirm-click --save
- Include
node_modules/confirm-click/confirm-click.js
- Add
confirm-click
module dependency to your app
Confirming ng-click
Works with regular boolean- or promise-returning functions.
<button ng-click="popAlert()" confirm-click="Want to see a popup?">pop alert</button>
Configure custom popup function
Use ConfirmClickProvider
function to set ask
function. This function
will be used for href
and ng-href
confirmation.
<script>
// just to show 3rd party confirm, should return a boolean
function ask(question) {
return confirm(question);
}
angular.module('ClickApp', ['confirm-click'])
.config(function (ConfirmClickProvider) {
ConfirmClickProvider.ask(ask);
});
</script>
<a ng-href="http://github.com" confirm-click="Go to github?">github.com</a>
Custom popup function for ng-click
Can return a promise, should resolve with false
to stop the action, or with true to continue.
For example to use alertify.js to confirm, we can use
<script>
angular.module('ClickApp', ['confirm-click'])
.config(function (ConfirmClickProvider) {
ConfirmClickProvider.ask(function (question) {
return new Promise(function (resolve) {
alertify.confirm(question, resolve);
});
});
})
</script>
<button ng-click="popAlert()" confirm-click="Want to see a popup?">pop alert</button>
A good library wrapping alertify into promise-returning methods is kensho/ng-alertify.
See demo page for live example.
Small print
Author: Gleb Bahmutov © 2015
License: MIT - do anything with the code, but don't blame me if it does not work.
Spread the word: tweet, star on github, etc.
Support: if you find any problems with this module, email / tweet / open issue on Github
MIT License
Copyright (c) 2015 Gleb Bahmutov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.