Wrap XMLHttpRequest in an angular $http-like promise.
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
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!');
});
});