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


TypeScript DOM.createTemplate方法代码示例

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


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

示例1: process

  process(parent: CompileElement, current: CompileElement, control: CompileControl) {
    var attrs = current.attrs();
    var templateBindings = attrs.get('template');
    var hasTemplateBinding = isPresent(templateBindings);

    // look for template shortcuts such as *ng-if="condition" and treat them as template="if
    // condition"
    MapWrapper.forEach(attrs, (attrValue, attrName) => {
      if (StringWrapper.startsWith(attrName, '*')) {
        var key = StringWrapper.substring(attrName, 1);  // remove the star
        if (hasTemplateBinding) {
          // 2nd template binding detected
          throw new BaseException(`Only one template directive per element is allowed: ` +
                                  `${templateBindings} and ${key} cannot be used simultaneously ` +
                                  `in ${current.elementDescription}`);
        } else {
          templateBindings = (attrValue.length == 0) ? key : key + ' ' + attrValue;
          hasTemplateBinding = true;
        }
      }
    });

    if (isPresent(parent)) {
      if (DOM.isTemplateElement(current.element)) {
        if (!current.isViewRoot) {
          var viewRoot = new CompileElement(DOM.createTemplate(''));
          viewRoot.inheritedProtoView = current.bindElement().bindNestedProtoView(viewRoot.element);
          // viewRoot doesn't appear in the original template, so we associate
          // the current element description to get a more meaningful message in case of error
          viewRoot.elementDescription = current.elementDescription;
          viewRoot.isViewRoot = true;

          this._moveChildNodes(DOM.content(current.element), DOM.content(viewRoot.element));
          control.addChild(viewRoot);
        }
      }
      if (hasTemplateBinding) {
        var newParent = new CompileElement(DOM.createTemplate(''));
        newParent.inheritedProtoView = current.inheritedProtoView;
        newParent.inheritedElementBinder = current.inheritedElementBinder;
        newParent.distanceToInheritedBinder = current.distanceToInheritedBinder;
        // newParent doesn't appear in the original template, so we associate
        // the current element description to get a more meaningful message in case of error
        newParent.elementDescription = current.elementDescription;

        current.inheritedProtoView = newParent.bindElement().bindNestedProtoView(current.element);
        current.inheritedElementBinder = null;
        current.distanceToInheritedBinder = 0;
        current.isViewRoot = true;
        this._parseTemplateBindings(templateBindings, newParent);

        this._addParentElement(current.element, newParent.element);
        control.addParent(newParent);
        DOM.remove(current.element);
      }
    }
  }
开发者ID:Salim-K,项目名称:angular,代码行数:57,代码来源:view_splitter.ts

示例2: load

 load(template) {
   if (isPresent(template.inline)) {
     return PromiseWrapper.resolve(DOM.createTemplate(template.inline));
   }
   if (isPresent(template.absUrl)) {
     var content = this._urlData[template.absUrl];
     if (isPresent(content)) {
       return PromiseWrapper.resolve(DOM.createTemplate(content));
     }
   }
   return PromiseWrapper.reject('Load failed');
 }
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:12,代码来源:integration_testbed.ts

示例3: load

  load(view: ViewDefinition): Promise<any> {
    if (isPresent(view.template)) {
      return PromiseWrapper.resolve(DOM.createTemplate(view.template));
    }

    if (isPresent(view.templateAbsUrl)) {
      var content = this._urlData.get(view.templateAbsUrl);
      return isPresent(content) ?
                 PromiseWrapper.resolve(DOM.createTemplate(content)) :
                 PromiseWrapper.reject(`Failed to fetch url "${view.templateAbsUrl}"`, null);
    }

    throw new BaseException('View should have either the templateUrl or template property set');
  }
开发者ID:cedriclam,项目名称:angular,代码行数:14,代码来源:compiler_common_tests.ts

示例4: load

  load(template: ViewDefinition) {
    if (isPresent(template.template)) {
      return PromiseWrapper.resolve(DOM.createTemplate(template.template));
    }

    if (isPresent(template.absUrl)) {
      var content = MapWrapper.get(this._urlData, template.absUrl);
      return isPresent(content) ?
                 PromiseWrapper.resolve(DOM.createTemplate(content)) :
                 PromiseWrapper.reject(`Failed to fetch url "${template.absUrl}"`, null);
    }

    return PromiseWrapper.reject('Load failed', null);
  }
开发者ID:B-Thapa,项目名称:angular,代码行数:14,代码来源:compiler_common_tests.ts

示例5: it

 it('should add entries without value as attribute to the element', () => {
   var rootElement = DOM.createTemplate('<div *varname></div>');
   var results = proceess(rootElement);
   expect(results[1].attrs().get('varname')).toEqual('');
   expect(results[1].inheritedElementBinder.propertyBindings).toEqual(new Map());
   expect(results[1].inheritedElementBinder.variableBindings).toEqual(new Map());
 });
开发者ID:goderbauer,项目名称:angular,代码行数:7,代码来源:view_splitter_spec.ts

示例6: 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


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