feat(compiler, ShadowDom): adds TemplateLoader using XHR.
Also adds css shimming for emulated shadow dom and makes the shadowDom strategy global to the application.
This commit is contained in:

committed by
Rado Kirov

parent
fcbdf02767
commit
746f85a621
7
modules/angular2/src/core/compiler/xhr/xhr.js
vendored
Normal file
7
modules/angular2/src/core/compiler/xhr/xhr.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import {Promise} from 'angular2/src/facade/async';
|
||||
|
||||
export class XHR {
|
||||
get(url: string): Promise<string> {
|
||||
return null;
|
||||
}
|
||||
}
|
12
modules/angular2/src/core/compiler/xhr/xhr_impl.dart
Normal file
12
modules/angular2/src/core/compiler/xhr/xhr_impl.dart
Normal file
@ -0,0 +1,12 @@
|
||||
import 'dart:async';
|
||||
import 'dart:html';
|
||||
import './xhr.dart' show XHR;
|
||||
|
||||
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'
|
||||
);
|
||||
}
|
||||
}
|
27
modules/angular2/src/core/compiler/xhr/xhr_impl.es6
Normal file
27
modules/angular2/src/core/compiler/xhr/xhr_impl.es6
Normal file
@ -0,0 +1,27 @@
|
||||
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {XHR} from './xhr';
|
||||
|
||||
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.complete(xhr.responseText);
|
||||
} else {
|
||||
completer.reject(`Failed to load ${url}`);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onerror = function() {
|
||||
completer.reject(`Failed to load ${url}`);
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
return completer.promise;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user