bindDirectiveHostProps function

void bindDirectiveHostProps(
  1. MatchedDirective directive,
  2. CompileElement compileElement
)

Implementation

void bindDirectiveHostProps(
  ir.MatchedDirective directive,
  CompileElement compileElement,
) {
  if (!directive.hasHostProperties) {
    return;
  }
  o.Expression detectHostChanges;
  if (directive.isComponent) {
    detectHostChanges = compileElement.componentView!.callMethod(
      'detectHostChanges',
      [DetectChangesVars.firstCheck],
    );
  } else {
    final directiveInstance =
        unwrapDirectiveInstance(directive.providerSource!.build());
    // For @Component-annotated classes that extend @Directive classes, i.e.:
    //
    // @Directive(...)
    // class D {
    //   @HostBinding()
    //   ...
    // }
    //
    // @Component(...)
    // class C extends D {}
    //
    // In this case, `directiveInstance` is `Instance of C`, which in case will
    // not have a  `detectHostChanges()` (if it did, it would have returned true
    // for `.directive.isComponent` above).
    if (directiveInstance == null) {
      return;
    }
    detectHostChanges = directiveInstance.callMethod(
      'detectHostChanges',
      [
        compileElement.component != null
            ? compileElement.componentView!
            : o.THIS_EXPR,
        compileElement.renderNode.toReadExpr(),
      ],
    );
  }
  compileElement.view!.detectChangesRenderPropertiesMethod.addStmt(
    detectHostChanges.toStmt(),
  );
}