Tobias Bosch 4f56628566 refactor(render): move services to right location
core/compiler/events -> render/dom/events
core/compiler/url_resolver -> services/url_resolver
core/compiler/xhr/* -> services/*
2015-04-02 10:35:27 -07:00

30 lines
742 B
JavaScript

import {Injectable} from 'angular2/di';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {XHR} from './xhr';
@Injectable()
export class XHRImpl extends XHR {
get(url: string): Promise<string> {
var completer = PromiseWrapper.completer();
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'text';
xhr.onload = function() {
var status = xhr.status;
if (200 <= status && status <= 300) {
completer.resolve(xhr.responseText);
} else {
completer.reject(`Failed to load ${url}`);
}
};
xhr.onerror = function() {
completer.reject(`Failed to load ${url}`);
};
xhr.send();
return completer.promise;
}
}