All Projects → johannesjo → Angular2 Promise Buttons

johannesjo / Angular2 Promise Buttons

Licence: mit
Chilled loading buttons for angular2

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Angular2 Promise Buttons

nodeJS examples
Server, routing, db examples using NodeJS v6
Stars: ✭ 34 (-59.52%)
Mutual labels:  angular2, promise
Angular2 Recaptcha
Angular 2 : Typescript component for Google reCaptcha
Stars: ✭ 81 (-3.57%)
Mutual labels:  angular2
Ng2 Fan Menu
Angular Fan Menu
Stars: ✭ 76 (-9.52%)
Mutual labels:  angular2
Vue Rawmodel
RawModel.js plugin for Vue.js v2. Form validation has never been easier!
Stars: ✭ 79 (-5.95%)
Mutual labels:  promise
Webworker Promise
Promise based wrapper for webworkers
Stars: ✭ 77 (-8.33%)
Mutual labels:  promise
Paperadmin
A flat admin dashboard using Angular JS 2/4
Stars: ✭ 80 (-4.76%)
Mutual labels:  angular2
Drip Ionic3
「水滴打卡」App Open Source Code Base On Ionic V3 Framework
Stars: ✭ 74 (-11.9%)
Mutual labels:  angular2
Vine
Python promises
Stars: ✭ 83 (-1.19%)
Mutual labels:  promise
Semaphore Ng2 Webpack
Stars: ✭ 81 (-3.57%)
Mutual labels:  angular2
Sake Core
Sake's core interface.
Stars: ✭ 78 (-7.14%)
Mutual labels:  promise
Angular2 Contacts Demo
Angular 2 (ng2) 通讯录例子
Stars: ✭ 78 (-7.14%)
Mutual labels:  angular2
Ngx Lazy Load Images
Image lazy load library for Angular 2+
Stars: ✭ 77 (-8.33%)
Mutual labels:  angular2
Wymaterialbutton
Interactive and fully animated Material Design button for iOS developers.
Stars: ✭ 80 (-4.76%)
Mutual labels:  button
Smalltalk
Promise-based Alert, Confirm and Prompt replacement
Stars: ✭ 76 (-9.52%)
Mutual labels:  promise
Angular Websocket
↖️ The missing Angular WebSocket module for connecting client applications to servers by @AngularClass
Stars: ✭ 1,242 (+1378.57%)
Mutual labels:  angular2
Angular2
Angular 2 Seed
Stars: ✭ 75 (-10.71%)
Mutual labels:  angular2
Ng2 Konva
Angular & Canvas - JavaScript library for drawing complex canvas graphics using Angular.
Stars: ✭ 78 (-7.14%)
Mutual labels:  angular2
Node Promisepipe
Safely pipe node.js streams while capturing all errors to a single promise
Stars: ✭ 79 (-5.95%)
Mutual labels:  promise
React Planet
A react lib for building circular menus in a very easy and handy way.
Stars: ✭ 83 (-1.19%)
Mutual labels:  button
Ngx Papaparse
Papa Parse wrapper for Angular
Stars: ✭ 83 (-1.19%)
Mutual labels:  angular2

npm version Build Status Coverage Status MIT license

angular2-promise-buttons is a simple module that let's you add a loading indicator to a button of your choice. Check out the demo!

Bug-reports or feature request as well as any other kind of feedback is highly welcome!

Getting started

Install it via npm:

npm install angular2-promise-buttons -S

And add it as a dependency to your main module

import {Angular2PromiseButtonModule} from 'angular2-promise-buttons';

@NgModule({
  imports: [
    Angular2PromiseButtonModule.forRoot(),
  ],
})
export class MainAppModule {
}

Using the buttons is easy. Just pass a promise to the directive:

<button (click)="someAction()" 
   [promiseBtn]="promiseSetBySomeAction">Click me to spin!</button>
export class SomeComponent {
    // some example async action, but this works with any promise
    someAction(){
      this.promiseSetBySomeAction = new Promise((resolve, reject) => {
        setTimeout(resolve, 2000);
      });
    }
}

Styling the button

To give you maximum flexibility there are no base styles coming with the directive, but it is easy to fix that! There are lots of free css-spinners out there. Just find one of your liking and add the css to your global stylesheet.

Ressources:

There are selectors you can use to style. There is the .is-loading class on the button, which is set, when the promise is pending and there is the <span class="btn-spinner"></span> element inside the button.

Configuration

Configuration is done via the forRoot method of the promise button module:

import {Angular2PromiseButtonModule} from 'angular2-promise-buttons';

@NgModule({
  imports: [
    Angular2PromiseButtonModule
      .forRoot({
        // your custom config goes here
        spinnerTpl: '<span class="btn-spinner"></span>',
        // disable buttons when promise is pending
        disableBtn: true,
        // the class used to indicate a pending promise
        btnLoadingClass: 'is-loading',
        // only disable and show is-loading class for clicked button, 
        // even when they share the same promise
        handleCurrentBtnOnly: false,
      }),
  ],
})
export class MainAppModule {
}

Using observables

When you're using the module with observables make sure to pass a subscription to the directive rather than an observable directly.

const FAKE_FACTORY = {
  initObservable: (): Observable<number> => {
    return new Observable(observer => {
      setTimeout(() => {
        observer.complete();
      }, 4000);
    });
  } 
};

// DO:
const observable = FAKE_FACTORY.initObservable();
this.passedToDirective = observable.subscribe(
// ...
);
  
// DON'T DO:
const observable = FAKE_FACTORY.initObservable();
this.passedToDirective = observable;

Using booleans

Is now also possible.

<button (click)="someAction()" 
   [promiseBtn]="isShowBoolean">Click!</button>

Contributing

Contribution guidelines: CONTRIBUTING.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].