Skip to content

NgModule.declarations forwardRef doesn't work for JIT #45741

Closed
@pauldraper

Description

@pauldraper

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

Had reported in #41801, but with insufficient detail.

For, using forwardRef for NgModule.declarations doesn't work.

import { CommonModule } from '@angular/common';
import { Component, forwardRef, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

@Component({
  selector: 'app-root',
  template: `
    <button type="button" (click)="on = !on">Toggle</button>
    <ng-container *ngIf="on">
      On
  </ng-container>
  <ng-container *ngIf="!on">
      Off
  </ng-container>
  `
})
export class AppComponent {
  on = false;
}


@NgModule({
  bootstrap: [forwardRef(() => AppComponent)],
  declarations: [forwardRef(() => AppComponent)],
  //declarations: [AppComponent],
  exports: [forwardRef(() => AppComponent)],
  imports: [BrowserModule, CommonModule],
})
export class AppModule {}

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Angular fails to resolve the `ngIf` directive.

Please provide the environment you discovered this bug in (run ng version)

Angular: 13.3.4
... common, compiler, compiler-cli, core, platform-browser
... platform-browser-dynamic

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1303.3
@angular-devkit/build-angular   13.3.3
@angular-devkit/core            13.3.3
@angular-devkit/schematics      13.3.3
@angular/cli                    13.3.3
@schematics/angular             13.3.3
rxjs                            7.5.5
typescript                      4.6.3


### Anything else?

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimebug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions