{"id":13777268,"url":"https://github.com/johannesjo/angular-promise-buttons","last_synced_at":"2025-05-11T11:33:08.617Z","repository":{"id":28662731,"uuid":"32182282","full_name":"johannesjo/angular-promise-buttons","owner":"johannesjo","description":"Chilled loading buttons for AngularJS","archived":true,"fork":false,"pushed_at":"2018-03-17T12:00:59.000Z","size":2478,"stargazers_count":154,"open_issues_count":3,"forks_count":32,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-05-02T00:54:09.637Z","etag":null,"topics":["angular","angular-directives","angularjs","promise","promise-buttons"],"latest_commit_sha":null,"homepage":"http://johannesjo.github.io/angular-promise-buttons/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johannesjo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-13T21:41:38.000Z","updated_at":"2024-02-27T04:52:37.000Z","dependencies_parsed_at":"2022-08-22T18:31:22.201Z","dependency_job_id":null,"html_url":"https://github.com/johannesjo/angular-promise-buttons","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johannesjo%2Fangular-promise-buttons","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johannesjo%2Fangular-promise-buttons/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johannesjo%2Fangular-promise-buttons/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johannesjo%2Fangular-promise-buttons/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johannesjo","download_url":"https://codeload.github.com/johannesjo/angular-promise-buttons/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225000788,"owners_count":17405073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular-directives","angularjs","promise","promise-buttons"],"created_at":"2024-08-03T18:00:40.706Z","updated_at":"2024-11-17T13:30:35.739Z","avatar_url":"https://github.com/johannesjo.png","language":"JavaScript","funding_links":[],"categories":["Directive"],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/angular-promise-buttons.svg)](https://badge.fury.io/js/angular-promise-buttons)\n[![Build Status](https://travis-ci.org/johannesjo/angular-promise-buttons.svg)](https://travis-ci.org/johannesjo/angular-promise-buttons?branch=master)\n[![Coverage Status](https://coveralls.io/repos/johannesjo/angular-promise-buttons/badge.svg?branch=master)](https://coveralls.io/r/johannesjo/angular-promise-buttons?branch=master)\n\nangular-promise-buttons\n===========\n\n*Chilled Buttons for AngularJS*\n\nFor Angular 2+ version [go here](https://github.com/johannesjo/angular2-promise-buttons).\n\nThere 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](http://johannesjo.github.io/angular-promise-buttons/#demo)!\n\nAlso you can play with the code on [Plnkr](http://plnkr.co/edit/yKrlohXVL15fRjTjZHBJ?p=preview).\n\n\n[Bug-reports or feature request](https://github.com/johannesjo/angular-promise-buttons/issues) as well as any other kind of **feedback is highly welcome!**\n\n## getting started\n\nInstall it via bower or npm\n```\nbower install angular-promise-buttons -S\n# or via npm\nnpm install angular-promise-buttons -S\n```\nand add `angularPromiseButtons` as dependency in your main module:\n```\nangular.module('yourApp',[\n  'angularPromiseButtons'\n]);\n```\n\nUsing the buttons is easy. Just return the promise in question in your service caller and you're good to go:\nYou can also directly return the promise via the function passed to `ng-click`:\n```html\n\u003cbutton ng-click=\"yourServiceCaller()\"\n        promise-btn\u003eClick me to spin!\u003c/button\u003e\n```\n\n```javascript\n// inside some controller\n$scope.yourServiceCaller = function ()\n{\n  return fakeFactory.method().then(...);\n};\n```\n### using it for forms\nFor 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:\n```html\n\u003cform ng-submit=\"yourServiceCaller()\"\n      promise-btn\u003e\n  \u003cbutton type=\"submit\"\u003eMyBtn\u003c/button\u003e\n\u003c/form\u003e\n```\n\n```javascript\n// inside some controller\n$scope.yourServiceCaller = function ()\n{\n  return fakeFactory.method().then(...);\n};\n```\n\n### alternative syntax and using $event\nThere 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:\n```html\n\u003cbutton ng-click=\"yourServiceCaller($event)\"\n        promise-btn=\"yourPromise\"\u003eMyBtn\u003c/button\u003e\n```\nNow you just have to assign a promise to ```yourPromise```:\n```javascript\n// inside some controller\n$scope.yourServiceCaller = function ()\n{\n  $scope.yourPromise = fakeFactory.method().then(...);\n  // this is now also possible\n  $event.preventDefault();\n};\n```\n\n\n\n## styling the button\nThe 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.\n\n**Ressources:**\n* http://cssload.net/\n* http://projects.lukehaas.me/css-loaders/\n* http://tobiasahlin.com/spinkit/\n\n\n## configuration\nThere are also some defaults for you to set, if you like. You can do this by using the ```angularPromiseButtonsProvider```:\n```javascript\nangular.module('exampleApp', [\n  'angularPromiseButtons'\n])\n.config(function (angularPromiseButtonsProvider)\n{\n  angularPromiseButtonsProvider.extendConfig({\n    spinnerTpl: '\u003cspan class=\"btn-spinner\"\u003e\u003c/span\u003e',\n    disableBtn: true,\n    btnLoadingClass: 'is-loading',\n    addClassToCurrentBtnOnly: false,\n    disableCurrentBtnOnly: false,\n    minDuration: false,\n    CLICK_EVENT: 'click',\n    CLICK_ATTR: 'ngClick',\n    SUBMIT_EVENT: 'submit',\n    SUBMIT_ATTR: 'ngSubmit',\n    BTN_SELECTOR: 'button'\n  });\n});\n```\n\n## change options via `promise-btn-options`\nYou can also change all the options (**but not the spinner template**) by specifying the options via `promise-btn-options`:\n```html\n\u003cbutton class=\"btn\"\n        ng-click=\"yourServiceCaller()\"\n        promise-btn-options=\"options\"\n        promise-btn=\"yourPromise\"\u003eMyBtn \u003cspan\u003eLook I'm nested content\u003c/span\u003e\n\u003c/button\u003e\n```\nNow you just have to assign a promise to ```yourPromise```:\n```javascript\n// inside some controller\n$scope.options = {\n  disableBtn: false,\n  btnLoadingClass: 'is-spinning'\n};\n$scope.yourServiceCaller = function ()\n{\n  $scope.yourPromise = fakeFactory.method().then(...);\n};\n```\n\nThats all the logic there is (for now). Adjusting the look and feel of the spinner can be done using your own styles.\n\n\n## ❤ contribute ❤\nI'm happy for any [issue or feature request](https://github.com/johannesjo/angular-promise-buttons/issues), 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](http://ngmodules.org/modules/angular-promise-buttons), tweet or even blog about it.\n\n`angular-promise-buttons` is published under the [The GNU Lesser General Public License V2.1](https://github.com/johannesjo/angular-promise-buttons/blob/master/LICENSE).\n\n## (possible) promising future features\n* [your feature request](https://github.com/johannesjo/angular-promise-buttons/issues)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohannesjo%2Fangular-promise-buttons","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohannesjo%2Fangular-promise-buttons","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohannesjo%2Fangular-promise-buttons/lists"}