ng-xhr-promisify

Wrap XMLHttpRequest in an angular $http-like promise

Usage no npm install needed!

<script type="module">
  import ngXhrPromisify from 'https://cdn.skypack.dev/ng-xhr-promisify';
</script>

README

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!');
  });
});