Giter VIP home page Giter VIP logo

ng-submission's Introduction

ng-submission Build Status

Keep track of pending/error states in Angular

Inspired by bendrucker/submission.

Install

$ npm install --save ng-submission

Usage

angular.module('myapp', [
  require('ng-submission')
])
  .controller('MyController', MyController)

function MyController ($http, ngSubmission) {
  var self = this

  var submission = ngSubmission()

  this.postForm = function (data) {
    console.log(submission) // => {pending: false, error: null}

    const promise = submission.submit($http.post('/submit', {data: data}))

    console.log(submission) // => {pending: true, error: null}

    return promise
      .then(function (response) {
        console.log(submission) // => {pending: false, error: null}
      })
      .catch(function (error) {
        console.log(submission) // => {pending: false, error: error}
      })
  }
}

Setup

Include 'ng-submission' in your angular module's dependencies:

// node module exports the string 'ng-submission' for convenience
angular.module('myApp', [
  require('ng-submission')
])
// otherwise, include the code first then the module name
angular.module('myApp', [
  'ng-submission'
])

API

service: ngSubmission: function () -> submission

Exposes the 'ngSubmission' service, which is a function that returns a new submission instance.

submission

Is an object, with three properties:

  • submission.submit: function(promise) - A function that takes a promise and starts a new submission.
  • submission.pending: Boolean - whether the submit is pending
  • submission.error: Object|null - if the previous submit errored, the error object from that submission. Otherwise, null.

License

MIT © Andrew Joslin

ng-submission's People

Contributors

ajoslin avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.