当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript PromiseWrapper.then方法代码示例

本文整理汇总了TypeScript中angular2/src/facade/async.PromiseWrapper.then方法的典型用法代码示例。如果您正苦于以下问题:TypeScript PromiseWrapper.then方法的具体用法?TypeScript PromiseWrapper.then怎么用?TypeScript PromiseWrapper.then使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在angular2/src/facade/async.PromiseWrapper的用法示例。


在下文中一共展示了PromiseWrapper.then方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: load

  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:B-Thapa,项目名称:angular,代码行数:27,代码来源:template_loader.ts

示例2: _createAppInjector

  zone.run(() => {
    // TODO(rado): prepopulate template cache, so applications with only
    // index.html and main.js are possible.

    var appInjector = _createAppInjector(appComponentType, componentInjectableBindings, zone);

    //TODO: get rid of the test bindings
    var renderer = appInjector.get(Renderer);
    var loader = appInjector.get(TemplateLoader);
    var inliner = appInjector.get(StyleInliner);
    //var loader = appInjector.get(DynamicComponentLoader);
    console.log(loader);

    PromiseWrapper.then(
        appInjector.asyncGet(appComponentRefToken),
        (componentRef) =>
        {
            var appChangeDetector = internalView(componentRef.hostView).changeDetector;
            // retrieve life cycle: may have already been created if injected in root component
            var lc = appInjector.get(LifeCycle);
            lc.registerWith(zone, appChangeDetector);
            lc.tick();  // the first tick that will bootstrap the app

            bootstrapProcess.resolve(new ApplicationRef(componentRef, appComponentType, appInjector));
        },

        (err, stackTrace) => {bootstrapProcess.reject(err, stackTrace)}
    );
  });
开发者ID:hdeshev,项目名称:angular-templates,代码行数:29,代码来源:application.ts

示例3: expectResponse

 function expectResponse(request, url, response, done = null) {
   function onResponse(text) {
     if (response === null) {
       throw `Unexpected response ${url} -> ${text}`;
     } else {
       expect(text).toEqual(response);
       if (isPresent(done))
         done();
     }
   }
   Object.defineProperty(onResponse, "parameters", {get: function() {
       return [[assert.type.string]];
     }});
   function onError(error) {
     if (response !== null) {
       throw `Unexpected error ${url}`;
     } else {
       expect(error).toEqual(`Failed to load ${url}`);
       if (isPresent(done))
         done();
     }
   }
   Object.defineProperty(onError, "parameters", {get: function() {
       return [[assert.type.string]];
     }});
   PromiseWrapper.then(request, onResponse, onError);
 }
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:27,代码来源:xhr_mock_spec.ts

示例4: compile

 compile(view: ViewDefinition): Promise<ProtoViewDto> {
   var tplPromise = this._viewLoader.load(view);
   return PromiseWrapper.then(
       tplPromise, (el) => this._compileTemplate(view, el, ViewType.COMPONENT), (e) => {
         throw new BaseException(`Failed to load the template for "${view.componentId}" : ${e}`);
       });
 }
开发者ID:cedriclam,项目名称:angular,代码行数:7,代码来源:compiler.ts

示例5: compile

 compile(template: ViewDefinition):Promise<ProtoViewDto> {
   var tplPromise = this._templateLoader.load(template);
   return PromiseWrapper.then(tplPromise,
     (el) => this._compileTemplate(template, el),
     (_) => { throw new BaseException(`Failed to load the template "${template.componentId}"`); }
   );
 }
开发者ID:tavwizard,项目名称:angular,代码行数:7,代码来源:compiler.ts

示例6: _inlineImports

  _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

示例7: it

 it('should throw if no Template found', inject([AsyncTestCompleter], (async) => {
   var injectorPromise = bootstrap(HelloRootMissingTemplate, testBindings, (e, t) => {
     throw e;
   });
   PromiseWrapper.then(injectorPromise, null, (reason) => {
     expect(reason.message).toContain('No template found for HelloRootMissingTemplate');
     async.done();
   });
 }));
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:9,代码来源:application_spec.ts

示例8: expectCompileError

 function expectCompileError(inlineTpl, errMessage, done) {
   tplResolver.setTemplate(MyComp, new Template({inline: inlineTpl}));
   PromiseWrapper.then(compiler.compile(MyComp), (value) => {
     throw new BaseException("Test failure: should not have come here as an exception was expected");
   }, (err) => {
     expect(err.message).toEqual(errMessage);
     done();
   });
 }
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:9,代码来源:integration_spec.ts


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