Skip to content

Wrap XMLHttpRequest in an angular $http-like promise

License

Notifications You must be signed in to change notification settings

martarsm/ng-xhr-promisify

 
 

Repository files navigation

ng-xhr-promisify

license release

Wrap XMLHttpRequest in an angular $http-like promise.

Installation

Directly from unpkg:

<script src="https://unpkg.com/ng-xhr-promisify@latest/dist/ng-xhr-promisify.min.js"></script>

With npm:

npm install --save ng-xhr-promisify

With bower:

bower install --save ng-xhr-promisify

Usage

import angular from 'angular';
import ngXhrPromisify from 'ng-xhr-promisify';

const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.github.com/repos/tiago/ng-xhr-promisify', true);
xhr.responseType = 'json';
xhr.send();

angular.module('App', [
  ngXhrPromisify
]).run(function (xhrPromisify) {
  xhrPromisify(xhr).then(response => {
    console.log(`${response.data.name}: ${response.data.description}`);
  }).catch(error => {
    console.log(`Error: ${error.status}`);
  }).finally(() => {
    console.log('Bye!');
  });
});

About

Wrap XMLHttpRequest in an angular $http-like promise

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%