@@ -1,15 +1,17 @@
|
||||
library angular2.src.services.xhr_impl;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:html';
|
||||
import 'dart:async' show Future;
|
||||
import 'dart:html' show HttpRequest;
|
||||
import 'package:angular2/di.dart';
|
||||
import './xhr.dart' show XHR;
|
||||
|
||||
@Injectable()
|
||||
class XHRImpl extends XHR {
|
||||
Future<String> get(String url) {
|
||||
return HttpRequest.request(url).then(
|
||||
(HttpRequest request) => request.responseText,
|
||||
onError: (Error e) => throw 'Failed to load $url');
|
||||
|
||||
return HttpRequest
|
||||
.request(url)
|
||||
.then((HttpRequest req) => req.responseText,
|
||||
onError: (_) => new Future.error('Failed to load $url'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ export class XHRImpl extends XHR {
|
||||
if (200 <= status && status <= 300) {
|
||||
completer.resolve(xhr.responseText);
|
||||
} else {
|
||||
completer.reject(`Failed to load ${url}`);
|
||||
completer.reject(`Failed to load ${url}`, null);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() { completer.reject(`Failed to load ${url}`); };
|
||||
xhr.onerror = function() { completer.reject(`Failed to load ${url}`, null); };
|
||||
|
||||
xhr.send();
|
||||
return completer.promise;
|
||||
|
||||
Reference in New Issue
Block a user