|
1 |
| -angular-prompt |
2 |
| -============== |
| 1 | +# angular-prompt |
3 | 2 |
|
4 |
| -Angular service to easily display prompt and confirmation modals |
| 3 | +> Angular service to easily display prompt and confirmation modals. |
| 4 | +
|
| 5 | +This library depends on [angular-ui-bootstrap](https://github.com/angular-ui/bootstrap). |
| 6 | + |
| 7 | +## Demo |
| 8 | + |
| 9 | +[Live Demo](http://cgross.github.io/angular-prompt/demo) |
| 10 | + |
| 11 | +## Getting Started |
| 12 | + |
| 13 | +Install with Bower or download the the files directly from the dist folder in the repo. |
| 14 | +```bash |
| 15 | +bower install angular-prompt --save |
| 16 | +``` |
| 17 | + |
| 18 | +Add `dist/angular-prompt.js` to your index.html. |
| 19 | + |
| 20 | +Add `cgPrompt` as a module dependency for your module. |
| 21 | + |
| 22 | +```js |
| 23 | +angular.module('your_app', ['ui.bootstrap','cgPrompt']); |
| 24 | +``` |
| 25 | + |
| 26 | +Now you can inject and use the `prompt` service. |
| 27 | + |
| 28 | +```js |
| 29 | +function MyCtrl($scope, prompt) { |
| 30 | + |
| 31 | + //simple confirmation |
| 32 | + prompt({ |
| 33 | + title: 'Delete this Thing?', |
| 34 | + message: 'Are you sure you want to do that?' |
| 35 | + }).then(function(){ |
| 36 | + //he hit ok and not cancel |
| 37 | + }); |
| 38 | + |
| 39 | + //ask the user for a string |
| 40 | + prompt({ |
| 41 | + title: 'Give me a name', |
| 42 | + message: 'What would you like to name it?', |
| 43 | + input: true, |
| 44 | + label: 'Name', |
| 45 | + value: 'Current name', |
| 46 | + values: ['other','possible','names'] |
| 47 | + }).then(function(name){ |
| 48 | + //the promise is resolved with the user input |
| 49 | + }); |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## API |
| 54 | + |
| 55 | +### prompt(options); |
| 56 | + |
| 57 | + - #### options.title |
| 58 | + Type: `String` |
| 59 | + Default: `''` |
| 60 | + The title for the dialog. |
| 61 | + |
| 62 | + - #### options.message |
| 63 | + Type: `String` |
| 64 | + Default: `''` |
| 65 | + The message inside the dialog. |
| 66 | + |
| 67 | + - #### options.input |
| 68 | + Type: `Boolean` |
| 69 | + Default: `false` |
| 70 | + Set to `true` if you wish to prompt the user for a text value. |
| 71 | + |
| 72 | + - #### options.label |
| 73 | + Type: `String` |
| 74 | + Default: `''` |
| 75 | + The label for the input if `input=true`. |
| 76 | + |
| 77 | + - #### options.value |
| 78 | + Type: `String` |
| 79 | + Default: `''` |
| 80 | + The initial value of the input if `input=true`. |
| 81 | + |
| 82 | + - #### options.values |
| 83 | + Type: `Array` of `String` |
| 84 | + Default: `undefined` |
| 85 | + A list of values available in a dropdown for the user to select as the input value. |
| 86 | + |
| 87 | + - #### options.buttons |
| 88 | + Type: `Array` of `Object` with properties `label`,`cancel`, and `primary` |
| 89 | + Default: `[{ label:'OK', primary: true }, { label:'Cancel', cancel: true }]` |
| 90 | + A list of the buttons to display on the dialog. |
| 91 | + |
| 92 | +The function returns a promise. That promise is resolved with either the button that was pressed, or in the case of input prompts, the value the user entered. If the user pressed a button where `cancel=true` or canceled the dialog another way (hit ESC, etc) then the promise is rejected. |
| 93 | + |
| 94 | +## Release History |
| 95 | + * v1.0.0 - Initial release. |
0 commit comments