ProviderElementContext constructor

ProviderElementContext(
  1. ProviderViewContext _rootProviderContext,
  2. ProviderElementContext? _parent,
  3. bool _isViewRoot,
  4. List<DirectiveAst> _directiveAsts,
  5. List<AttrAst> attrs,
  6. List<ReferenceAst> refs,
  7. SourceSpan? _sourceSpan,
)

Implementation

ProviderElementContext(
    this._rootProviderContext,
    this._parent,
    this._isViewRoot,
    this._directiveAsts,
    List<AttrAst> attrs,
    List<ReferenceAst> refs,
    this._sourceSpan) {
  for (var attrAst in attrs) {
    _attrs[attrAst.name] = attrAst.value;
  }
  final directivesMeta = _directiveMetadataFromAst(_directiveAsts);
  // Make a list of all providers required by union of all directives
  // including components themselves.
  final resolver = _ProviderResolver(directivesMeta, _sourceSpan);
  _allProviders = resolver.resolve();

  // Get content queries since we need to eagerly create providers to serve
  // values for component @ContentChild/@ContentChildren at ngOnInit time.
  _contentQueries = _getContentQueries(directivesMeta);
  var queriedTokens = CompileTokenMap<bool>();
  for (var provider in _allProviders.values) {
    _addQueryReadsTo(provider.token, queriedTokens);
  }
  // For each #ref, add the read type as a token to queries.
  for (var refAst in refs) {
    _addQueryReadsTo(CompileTokenMetadata(value: refAst.name), queriedTokens);
  }
  // If any content query asks to read ViewContainerRef, mark
  // ProviderElementContext to require view container.
  if (queriedTokens.get(identifierToken(Identifiers.viewContainerRef)) !=
      null) {
    _requiresViewContainer = true;
  }
  // Create the providers that we know are eager first.
  for (var provider in _allProviders.values) {
    var eager = provider.eager || queriedTokens.get(provider.token) != null;
    if (eager) {
      _getOrCreateLocalProvider(provider.providerType, provider.token,
          eager: true);
    }
  }
}