Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adamweeks/angular-defer-alert
Angular service to promisify $window alerts, confirms and prompts.
https://github.com/adamweeks/angular-defer-alert
Last synced: 15 days ago
JSON representation
Angular service to promisify $window alerts, confirms and prompts.
- Host: GitHub
- URL: https://github.com/adamweeks/angular-defer-alert
- Owner: adamweeks
- License: mit
- Created: 2015-11-19T19:45:23.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-19T20:43:57.000Z (about 9 years ago)
- Last Synced: 2024-09-27T09:29:14.701Z (3 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# angular-defer-alert
Angular service to promisify $window alerts, confirms and prompts.## Proposal
Do you want to use `$window.confirm` in a promise chain, but are too lazy to figure out how?
Well then, this is the service for you!## Usage
### Confirms
Confirmations are great to insert in a process. They resolve successfully with an "OK" click. They are rejected when a user clicks "Cancel".
```javascript
MyDonutService
.getDonuts(12)
.then(function(donutsFetched) {
var confirmMessage = 'Are you sure you want to eat ' + donutsFetched + ' donuts?';
DeferAlertService.openConfirm(confirmMessage)
.then(function() {
// User wants to eat donuts!
return true;
})
.catch(function() {
// User does not want to eat donuts
return false;
});
});
```### Prompts
Prompts ask a user for input before continuing. They resolve successfully with an "OK" click and provide the entered value. They are rejected when a user clicks "Cancel".
```javascript
var promptMesage = 'How many donuts do you want to eat?';
var defaultValue = '12';
DeferAlertService.openPrompt(promptMessage, defaultValue)
.then(function(donutAmount) {
MyDonutService
.getDonuts(donutAmount)
.then(function(donutsFetched) {
var confirmMessage = 'Are you sure you want to eat ' + donutsFetched + ' donuts?';
DeferAlertService.openConfirm(confirmMessage)
.then(function() {
// User wants to eat donuts!
return true;
})
.catch(function() {
// User does not want to eat donuts
return false;
});
});
});
```### Alerts
Since alerts don't really require a promise, we immediately resolve them, making for a very boring demo.
```javascript
MyAwesomeService
.doThing()
.then(function(textToAlert) {
DeferAlertService.openAlert(textToAlert);
});
```