• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript xhr.XHR类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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');
  }
开发者ID:Mariem-07,项目名称:angular,代码行数:27,代码来源:template_loader.ts


示例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;
    }));
  }
开发者ID:baraksu,项目名称:angular,代码行数:59,代码来源:style_inliner.ts


示例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');
  }
开发者ID:tavwizard,项目名称:angular,代码行数:21,代码来源:template_loader.ts


示例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');
  }
开发者ID:188799958,项目名称:angular,代码行数:23,代码来源:template_loader.ts



注:本文中的angular2/src/services/xhr.XHR类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript benchmark_util.bindAction函数代码示例发布时间:2022-05-25
下一篇:
TypeScript url_resolver.UrlResolver类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap