npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-ladda

v0.0.3

Published

an angular module to use ladda-loaders with ease

Downloads

1

Readme

ng-ladda

an angular module to use ladda with ease. This module is different from other angular ladda modules you find on github.

WORK IN PROGRESS

Todo:

  • ~~clean up callbacks~~
  • add unit tests

Demo

demo

Problem

Do you know ladda? I love to use these button animations as load indicators in my angular apps. But their usage always came with a drawback .. I have to manage the loading state of the buttons somehow in my app. That means boilercode in my controllers .. even if you have an directive to handle ladda.

e.g., some typical controller and template code:

angular.module('app').controller('SomeController', SomeController);

SomeController.$inject = ['SomeResouce'];
function SomeController($resource) {
  var vm = this;

  vm.load = load;
  vm.data = {};
  vm.meta = {
    ladda: false;
  }

  function load() {
    vm.meta.ladda = true;
    $resource.query().$promise.then(onSuccess).finally(onDone);
  }

  function onSuccess(data) {
    vm.data = data;
  }

  function onDone() {
    vm.meta.ladda = false;
  }
}
  ...
    <button ladda="vm.meta.ladda" ng-click="vm.load()">Load something!</button>
  ...

And this for every controller that handles some sort of http load/save/whatever. That sums up to a lot of boilerplate code just to handle ladda buttons

Solution

I think we can do better. I think we can do this without ANY boilerplate code in our controllers. Instead of telling every button to start or stop an indicator, we link every indicator to a http route. Becuase thats what it indicates, right?.

Lets rewrite the example above with ng-ladda:

angular.module('app').run(Setup).controller('SomeController', SomeController);

Setup.$inject = ['ngLaddaService'];
function Setup($ladda) {
  // link a httpRequest to a unique event/name
  $ladda.register('GET', '/some/resource/query', 'query-some-resource');
}

SomeController.$inject = ['SomeResouce'];
function SomeController($resource) {
  var vm = this;

  vm.load = load;
  vm.data = {};

  function load() {
    $resource.query().$promise.then(onSuccess);
  }

  function onSuccess(data) {
    vm.data = data;
  }
}
  ...
    <button ng-ladda="query-some-resource" ng-click="vm.load()">Load something!</button>
  ...

No boilerplate code in your controller (:cat:)

How it works

ng-ladda hooks into angular's $http provider and observes every request to trigger registered load-indicators via named events. The overhead to do this is very minimal.

Usage :monkey:

install via npm:

npm install ng-ladda

Include js file via script tag or in your browserify bundle via require('ng-ladda');:

<script src="node_modules/ng-ladda/dist/ng-ladda.js" type="text/javascript"></script>

Setup your angular app:

angular.module('myapp', ['io.dennis.ladda']).config(Config);

Config.$inject = ['ngLaddaService']
function Config($ladda) {
  // setup your routes ..
  $ladda.register('GET', '/some/resource/query', 'query-some-resource');
}

Use the ladda-directive in your HTML:

  ...
    <button ng-ladda="query-some-resource" ng-click="vm.load()">Load something!</button>
  ...