ng-clickdirective that automatically sets the element to disabled if the handler would return a promise.
- angular.js version >1.2+
- following es5 functions:
angular.module('MyApp', [ 'ngAutodisable', ... ]); ``` If that's done then just follow those simple steps: 1. just attach `ng-autodisable` directive to the element which happens to have `ng-click` directive OR a form that has the `ng-submit` directive. 2. ??? 3. profit! #### On an element
#### On a form
... <button type="submit">Submit</button>
The button with type `submit` within the form will be disabled. #### Loading class You can *optionally* add a list of classes which will be added to the element while this is disabled. This is useful to add a spinner or something similar.
ng-autodisable-class="class1 class2" ng-autodisable> Do something
ng-autodisable-class="class1 class2" ng-autodisable> ... <button type="submit">Submit</button>
The button with type `submit` within the form will get the class. ### Demo --- A quick demo is available at [jsfiddle](http://jsfiddle.net/kirstein/wXnks/embedded/result/) ### How it works --- When `ngClick` and `ngAutodisable` are on the same element then `ngAutodisable` overwrites the handler for `click` event. The default `ngClick` action is recreated _(and passes all the angular specs)_. If the click handlers result happens to be a `promise` _(`$http` or `$q`)_ then the element attribute `disabled` will be set as true. If the promise fulfills then the element `disabled` attribute will be removed. This also works with multiple click handlers, given that click handlers are separated by `;` as such:
npm install bower install grunt test grunt build ```
If there are multiple click handlers then the element disabled style will be removed after the last promise resolves. ### Note --- Throws an exception `ngAutodisable requires ngClick attribute in order to work` if `ngAutodisable` is on an element without `ngClick`. ### Devel ---