Fork me on GitHub

Angular promise react

An angular library for making promise spinners and buttons that show the state of their call live.

Installation

angular-promise-react can be downloaded with bower:

bower install angular-promise-react --save

or you can download the latest version from github:

Latest release

Include angular-promise-react's script tag after angularjs' one

<script type="text/javascript" src="path/to/promise/react/angular-promise-react.min.js"></script>

Inject promise-react directive into your angular module:

angular.module('myApp', ['promise-react'])

Usage

<... promise-button="deferredCall()" >

Use this directive as attribute of your button. It will bind to click on the specified element and will run the function spedified as value when the button is pressed. This call should return a promise for the button to behave properly.

Makes the variables status and state available in the scope.

<... promise-button="deferredCall()" promise-trigger="event" >

Add a promise-trigger attribute to specify a custom event the action should be binded to. Any event jQuey can bind to will work

<... when-promise="status">

Works exactly like an ngIf directive except that it will only render when the value provided matches the current button status.

Possible statuses are:

If when-promise is used with no attributes it will default to match any state but idle.

<... when-progress="state">

Similar to when-promise but it's value will be matched against the current state (last value notified through the promise).

If when-promise is used with no attributes it will default to match any loading status: loading and intermediate.

<promise-default> label </promise-default>

It will prepare a default button using some provided templates (that can be overriden in app.config). By default it assumes font-awesome is begin used.

Whatever is placed inside the tag will be displayed when the status is idle. When loading it will display two arrows spinning and a check-mark when done.

Examples

This library has been designed with extensibility and flexibility in mind. Here you have some of the most common use cases:

Simplest button

Button built with minimum markup. It has been designed to be used with font-awesome but its fully customizable (see next example). You can only choose what should be displayed when the button is idle.

Simplest button (customized)

All the states of a button depend on templates that can be configured in your app.config method. This is perfect if you want all the buttons in your app to behave the same except for the title they have.

Fully featured button

Example of all the directives available being used