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


TypeScript DOM.isTemplateElement方法代码示例

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


在下文中一共展示了DOM.isTemplateElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: constructor

 constructor({elementBinders,
   element,
   isRootView}) {
   this.element = element;
   this.elementBinders = elementBinders;
   this.isTemplateElement = DOM.isTemplateElement(this.element);
   this.isRootView = isRootView;
   this.rootBindingOffset = (isPresent(this.element) && DOM.hasClass(this.element, NG_BINDING_CLASS)) ? 1 : 0;
 }
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:9,代码来源:proto_view.ts

示例3: process

 process(parent, current, control) {
   var attrs = current.attrs();
   var templateBindings = MapWrapper.get(attrs, 'template');
   var hasTemplateBinding = isPresent(templateBindings);
   MapWrapper.forEach(attrs, (attrValue, attrName) => {
     if (StringWrapper.startsWith(attrName, '*')) {
       var key = StringWrapper.substring(attrName, 1);
       if (hasTemplateBinding) {
         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.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.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:gdi2290,项目名称:sample-Angular2,代码行数:43,代码来源:view_splitter.ts

示例4: constructor

 constructor(template, protoChangeDetector, shadowDomStrategy, parentProtoView = null) {
   this.element = template;
   this.elementBinders = [];
   this.variableBindings = MapWrapper.create();
   this.protoLocals = MapWrapper.create();
   this.protoChangeDetector = protoChangeDetector;
   this.parentProtoView = parentProtoView;
   this.textNodesWithBindingCount = 0;
   this.elementsWithBindingCount = 0;
   this.instantiateInPlace = false;
   this.rootBindingOffset = (isPresent(this.element) && DOM.hasClass(this.element, NG_BINDING_CLASS)) ? 1 : 0;
   this.isTemplateElement = DOM.isTemplateElement(this.element);
   this.shadowDomStrategy = shadowDomStrategy;
   this._viewPool = new ViewPool(VIEW_POOL_CAPACITY);
   this.stylePromises = [];
   this.eventHandlers = [];
   this.bindingRecords = [];
   this._directiveMementosMap = MapWrapper.create();
   this._variableBindings = null;
   this._directiveMementos = null;
 }
开发者ID:gdi2290,项目名称:sample-Angular2,代码行数:21,代码来源:view.ts

示例5: process

  process(parent:CompileElement, current:CompileElement, control:CompileControl) {
    var attrs = current.attrs();
    var classList = current.classList();

    var cssSelector = new CssSelector();
    var nodeName = DOM.nodeName(current.element);
    cssSelector.setElement(nodeName);
    for (var i=0; i < classList.length; i++) {
      cssSelector.addClassName(classList[i]);
    }

    MapWrapper.forEach(attrs, (attrValue, attrName) => {
      cssSelector.addAttribute(attrName, attrValue);
    });

    var viewportDirective;
    var componentDirective;
    // Note: We assume that the ViewSplitter already did its work, i.e. template directive should
    // only be present on <template> elements!
    var isTemplateElement = DOM.isTemplateElement(current.element);

    this._selectorMatcher.match(cssSelector, (selector, directiveIndex) => {
      var elementBinder = current.bindElement();
      var directive = this._directives[directiveIndex];
      var directiveBinder = elementBinder.bindDirective(directiveIndex);
      current.compileChildren = current.compileChildren && directive.compileChildren;
      if (isPresent(directive.properties)) {
        MapWrapper.forEach(directive.properties, (bindConfig, dirProperty) => {
          this._bindDirectiveProperty(dirProperty, bindConfig, current, directiveBinder);
        });
      }
      if (isPresent(directive.hostListeners)) {
        MapWrapper.forEach(directive.hostListeners, (action, eventName) => {
          this._bindDirectiveEvent(eventName, action, current, directiveBinder);
        });
      }
      if (isPresent(directive.setters)) {
        ListWrapper.forEach(directive.setters, (propertyName) => {
          elementBinder.bindPropertySetter(propertyName);
        });
      }
      if (isPresent(directive.readAttributes)) {
        ListWrapper.forEach(directive.readAttributes, (attrName) => {
          elementBinder.readAttribute(attrName);
        });
      }
      if (directive.type === DirectiveMetadata.VIEWPORT_TYPE) {
        if (!isTemplateElement) {
          throw new BaseException(`Viewport directives need to be placed on <template> elements or elements ` +
          `with template attribute - check ${current.elementDescription}`);
        }
        if (isPresent(viewportDirective)) {
          throw new BaseException(`Only one viewport directive is allowed per element - check ${current.elementDescription}`);
        }
        viewportDirective = directive;
      } else {
        if (isTemplateElement) {
          throw new BaseException(`Only template directives are allowed on template elements - check ${current.elementDescription}`);
        }
        if (directive.type === DirectiveMetadata.COMPONENT_TYPE) {
          if (isPresent(componentDirective)) {
            throw new BaseException(`Only one component directive is allowed per element - check ${current.elementDescription}`);
          }
          componentDirective = directive;
          elementBinder.setComponentId(directive.id);
        }
      }
    });
  }
开发者ID:tavwizard,项目名称:angular,代码行数:69,代码来源:directive_parser.ts


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