CompileElement constructor

CompileElement(
  1. CompileElement? parent,
  2. CompileView? view,
  3. int? nodeIndex,
  4. NodeReference renderNode,
  5. TemplateAst? sourceAst,
  6. CompileDirectiveMetadata? component,
  7. List<CompileDirectiveMetadata> _directives,
  8. List<ProviderAst> _resolvedProvidersArray,
  9. bool hasViewContainer,
  10. bool hasEmbeddedView,
  11. List<ReferenceAst> references, {
  12. Expression? componentView,
  13. bool hasTemplateRefQuery = false,
  14. bool isHtmlElement = false,
})

Implementation

CompileElement(
  CompileElement? parent,
  CompileView? view,
  int? nodeIndex,
  NodeReference renderNode,
  this.sourceAst,
  this.component,
  this._directives,
  this._resolvedProvidersArray,
  this.hasViewContainer,
  this.hasEmbeddedView,
  List<ReferenceAst> references, {
  this.componentView,
  this.hasTemplateRefQuery = false,
  this.isHtmlElement = false,
}) : super(parent, view, nodeIndex, renderNode) {
  _providers = ProviderResolver(this, parent?._providers);
  if (references.isNotEmpty) {
    for (final reference in references) {
      final token = reference.value;
      referenceTokens[reference.name] = token;
      _publishesTemplateRef = _publishesTemplateRef ||
          token != null && token.equalsTo(Identifiers.TemplateRefToken);
    }
  }

  // Create new ElementRef(_el_#) expression and provide as instance.
  elementRef = o
      .importExpr(Identifiers.ElementRef)
      .instantiate([renderNode.toReadExpr()]);

  _providers.add(Identifiers.ElementRefToken, elementRef);
  _providers.add(Identifiers.ElementToken, renderNode.toReadExpr());
  _providers.add(Identifiers.HtmlElementToken, renderNode.toReadExpr());
  var readInjectorExpr =
      o.InvokeMemberMethodExpr('injector', [o.literal(this.nodeIndex)]);
  _providers.add(Identifiers.InjectorToken, readInjectorExpr);

  if (hasViewContainer || hasEmbeddedView) {
    appViewContainer = view!.createViewContainer(
      renderNode,
      nodeIndex!,
      !hasViewContainer,
      isRootElement ? null : parent!.nodeIndex,
    );
    _providers.add(Identifiers.ViewContainerToken, appViewContainer!);
  }

  // This logic was copied from the setter for `componentView`, which was
  // removed when `componentView` was made final (as there was no need for it
  // to ever be reassigned).
  if (componentView != null) {
    final indexCount = component!.template!.ngContentSelectors.length;
    for (var i = 0; i < indexCount; i++) {
      contentNodesByNgContentIndex.add([]);
    }
  }
}