• This repository has been archived on 09/Jan/2023
  • Stars
    star
    153
  • Rank 243,368 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Chilled loading buttons for AngularJS

npm version Build Status Coverage Status

angular-promise-buttons

Chilled Buttons for AngularJS

For Angular 2+ version go here.

There are cool loading buttons out there for angular. Only thing which annoys me, is that you (most of the times) have to manually trigger their loading state via a boolean which leads to a bit of repetition, declaring those again and again. angular-promise-buttons exists to take away some of that, by handling the loading state directly by passing the promise. Saves you at least two lines of code every time. Check out the DEMO!

Also you can play with the code on Plnkr.

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

getting started

Install it via bower or npm

bower install angular-promise-buttons -S
# or via npm
npm install angular-promise-buttons -S

and add angularPromiseButtons as dependency in your main module:

angular.module('yourApp',[
  'angularPromiseButtons'
]);

Using the buttons is easy. Just return the promise in question in your service caller and you're good to go: You can also directly return the promise via the function passed to ng-click:

<button ng-click="yourServiceCaller()"
        promise-btn>Click me to spin!</button>
// inside some controller
$scope.yourServiceCaller = function ()
{
  return fakeFactory.method().then(...);
};

using it for forms

For using the promise buttons with ng-submit you need to apply them to the form directive and add `type="submit" to the buttons you want to show a loader for:

<form ng-submit="yourServiceCaller()"
      promise-btn>
  <button type="submit">MyBtn</button>
</form>
// inside some controller
$scope.yourServiceCaller = function ()
{
  return fakeFactory.method().then(...);
};

alternative syntax and using $event

There is also an alternative syntax, which allows you to share promises between buttons (and possibly other directives) and is especially useful, if you want to use the $event somehow:

<button ng-click="yourServiceCaller($event)"
        promise-btn="yourPromise">MyBtn</button>

Now you just have to assign a promise to yourPromise:

// inside some controller
$scope.yourServiceCaller = function ()
{
  $scope.yourPromise = fakeFactory.method().then(...);
  // this is now also possible
  $event.preventDefault();
};

styling the button

The base-styles might not be overwhelmingly sexy, 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.

Ressources:

configuration

There are also some defaults for you to set, if you like. You can do this by using the angularPromiseButtonsProvider:

angular.module('exampleApp', [
  'angularPromiseButtons'
])
.config(function (angularPromiseButtonsProvider)
{
  angularPromiseButtonsProvider.extendConfig({
    spinnerTpl: '<span class="btn-spinner"></span>',
    disableBtn: true,
    btnLoadingClass: 'is-loading',
    addClassToCurrentBtnOnly: false,
    disableCurrentBtnOnly: false,
    minDuration: false,
    CLICK_EVENT: 'click',
    CLICK_ATTR: 'ngClick',
    SUBMIT_EVENT: 'submit',
    SUBMIT_ATTR: 'ngSubmit',
    BTN_SELECTOR: 'button'
  });
});

change options via promise-btn-options

You can also change all the options (but not the spinner template) by specifying the options via promise-btn-options:

<button class="btn"
        ng-click="yourServiceCaller()"
        promise-btn-options="options"
        promise-btn="yourPromise">MyBtn <span>Look I'm nested content</span>
</button>

Now you just have to assign a promise to yourPromise:

// inside some controller
$scope.options = {
  disableBtn: false,
  btnLoadingClass: 'is-spinning'
};
$scope.yourServiceCaller = function ()
{
  $scope.yourPromise = fakeFactory.method().then(...);
};

Thats all the logic there is (for now). Adjusting the look and feel of the spinner can be done using your own styles.

❀ contribute ❀

I'm happy for any issue or feature request, you might encounter or want to have. Even a one liner is better, than no feedback at all. Pull requests are also highly welcome. Just fork the repository, clone it and run grunt serve for development. Another important factor is the number of developers using and thus testing angular-promise-buttons. Tell your fellow programmers, say that you use it on ng-modules, tweet or even blog about it.

angular-promise-buttons is published under the The GNU Lesser General Public License V2.1.

(possible) promising future features

More Repositories

1

super-productivity

Super Productivity is an advanced todo list app with integrated Timeboxing and time tracking capabilities. It also comes with integrations for Jira, Gitlab, GitHub and Open Project.
TypeScript
11,214
star
2

linux-window-session-manager

A tool to store and reload open windows and window positions for x11 desktops like unity and gnome.
TypeScript
394
star
3

angular-material-css-vars

Little library to use css variables with @angular/material
SCSS
193
star
4

ng-fab-form

Convenient forms for Angular with no extra markup? Fabulous!
JavaScript
172
star
5

super-productivity-android

Android App for Super Productivity (https://super-productivity.com/)
Kotlin
105
star
6

gnome-shell-extension-window-session-manager

An indicator that let's you save and restore your open apps and the window positions and arrangements over multiple real and virtual displays.
JavaScript
91
star
7

angular2-promise-buttons

Chilled loading buttons for angular2
TypeScript
86
star
8

generator-angular-auto-admin-loopback

Generator for automatic CRUD angular backend for loopback apps and apis
JavaScript
32
star
9

generator-modular-angular

A truly modular yeoman generator for AngularJS all device apps.
JavaScript
21
star
10

angular-material-sass-files

The sass files of the angular-material repository
CSS
20
star
11

super-productivity-themes

The repository for user made themes for Super Productivity <3
SCSS
18
star
12

sp2

Super Productivity2
TypeScript
11
star
13

generator-angular2-lib

A generator for angular 2 libraries with all the basic stuff setup to get you started quickly.
TypeScript
9
star
14

rainbow-bash-unicorn

Awesome happy rainbow bash theme with unicorn inside!!!!
8
star
15

super-productivity-ios

Repository of the iOS app for Super Productivity
7
star
16

super-productivity-chrome-extension

Allows communication with jira and idle time tracking for super productivity inside the browser.
JavaScript
7
star
17

linux-window-session-manger-indicator

TypeScript
6
star
18

angular-auto-forms

Auto form markup helper
JavaScript
6
star
19

bumcss

Scalable css architecture for web apps and websites
6
star
20

procrastinate-somewhere-else

A little program to keep you away from the computer from a certain point of time, via a message, shutting down or going to sleep mode.
JavaScript
5
star
21

gps-recorder

Records the GPS position over time
JavaScript
5
star
22

direct-video

Chrome extension to directly play videos in a new window in the native video player.
JavaScript
2
star
23

pods-wp-cli

Pods WP-CLI package
PHP
2
star
24

angular-auto-admin-looopback

JavaScript
2
star
25

clone-rename

Little script to clone a directory and rename all files with a certain pattern as well as all variable names in it.
JavaScript
2
star
26

chrome-extension-simple-vocabulary-trainer

Simple vocabulary trainer using chrome notifications. Uses a custom vocabulary list to remind you in a given interval of your vocabulary.
JavaScript
2
star
27

gnome-shell-extension-super-productivity

The companion gnome shell extension for super productivity
JavaScript
2
star
28

johannesjo.github.io

my github pages
1
star
29

cover-img

Simple jQuery Cover IMG plugin
JavaScript
1
star
30

git-count

...
1
star