本文整理汇总了TypeScript中angular2/src/services/xhr.XHR类的典型用法代码示例。如果您正苦于以下问题:TypeScript XHR类的具体用法?TypeScript XHR怎么用?TypeScript XHR使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XHR类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: BaseException
load(template: ViewDefinition): Promise</*element*/ any> {
if (isPresent(template.template)) {
return PromiseWrapper.resolve(DOM.createTemplate(template.template));
}
var url = template.absUrl;
if (isPresent(url)) {
var promise = StringMapWrapper.get(this._htmlCache, url);
if (isBlank(promise)) {
// TODO(vicb): change error when TS gets fixed
// https://github.com/angular/angular/issues/2280
// throw new BaseException(`Failed to fetch url "${url}"`);
promise = PromiseWrapper.then(this._xhr.get(url), html => {
var template = DOM.createTemplate(html);
return template;
}, _ => PromiseWrapper.reject(new BaseException(`Failed to fetch url "${url}"`), null));
StringMapWrapper.set(this._htmlCache, url, promise);
}
// We need to clone the result as others might change it
// (e.g. the compiler).
return promise.then((tplElement) => DOM.clone(tplElement));
}
throw new BaseException('View should have either the url or template property set');
}
示例2: SyncAsyncResult
_inlineImports(cssText: string, baseUrl: string,
inlinedUrls: List<string>): SyncAsyncResult<string> {
var partIndex = 0;
var parts = StringWrapper.split(cssText, _importRe);
if (parts.length === 1) {
// no @import rule found, return the original css
return new SyncAsyncResult(cssText, null);
}
var promises = [];
while (partIndex < parts.length - 1) {
// prefix is the content before the @import rule
var prefix = parts[partIndex];
// rule is the parameter of the @import rule
var rule = parts[partIndex + 1];
var url = _extractUrl(rule);
if (isPresent(url)) {
url = this._urlResolver.resolve(baseUrl, url);
}
var mediaQuery = _extractMediaQuery(rule);
var promise;
if (isBlank(url)) {
promise = PromiseWrapper.resolve(`/* Invalid import rule: "@import ${rule};" */`);
} else if (ListWrapper.contains(inlinedUrls, url)) {
// The current import rule has already been inlined, return the prefix only
// Importing again might cause a circular dependency
promise = PromiseWrapper.resolve(prefix);
} else {
ListWrapper.push(inlinedUrls, url);
promise = PromiseWrapper.then(this._xhr.get(url), (rawCss) => {
// resolve nested @import rules
var inlinedCss = this._inlineImports(rawCss, url, inlinedUrls);
if (isPresent(inlinedCss.asyncResult)) {
// wait until nested @import are inlined
return inlinedCss.asyncResult.then(
(css) => {return prefix + this._transformImportedCss(css, mediaQuery, url) + '\n'});
} else {
// there are no nested @import, return the css
return prefix + this._transformImportedCss(inlinedCss.syncResult, mediaQuery, url) +
'\n';
}
}, (error) => `/* failed to import ${url} */\n`);
}
ListWrapper.push(promises, promise);
partIndex += 2;
}
return new SyncAsyncResult(null, PromiseWrapper.all(promises).then(function(cssParts) {
var cssText = cssParts.join('');
if (partIndex < parts.length) {
// append then content located after the last @import rule
cssText += parts[partIndex];
}
return cssText;
}));
}
示例3: BaseException
load(template: ViewDefinition):Promise<any> {
if (isPresent(template.template)) {
return PromiseWrapper.resolve(DOM.createTemplate(template.template));
}
var url = template.absUrl;
if (isPresent(url)) {
var promise = StringMapWrapper.get(this._htmlCache, url);
if (isBlank(promise)) {
promise = this._xhr.get(url).then(function (html) {
var template = DOM.createTemplate(html);
return template;
});
StringMapWrapper.set(this._htmlCache, url, promise);
}
return promise;
}
throw new BaseException('View should have either the url or template property set');
}
示例4: BaseException
load(template: ViewDefinition): Promise</*element*/ any> {
if (isPresent(template.template)) {
return PromiseWrapper.resolve(DOM.createTemplate(template.template));
}
var url = template.absUrl;
if (isPresent(url)) {
var promise = StringMapWrapper.get(this._htmlCache, url);
if (isBlank(promise)) {
promise = this._xhr.get(url).then(function(html) {
var template = DOM.createTemplate(html);
return template;
});
StringMapWrapper.set(this._htmlCache, url, promise);
}
// We need to clone the result as others might change it
// (e.g. the compiler).
return promise.then((tplElement) => DOM.clone(tplElement));
}
throw new BaseException('View should have either the url or template property set');
}