Skip to content

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

Closed

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_

Activity

  1. added a commit that references this issue on Apr 24, 2022
    5b55f9f
  2. added
    area: core
    on Apr 25, 2022
  3. added this to the needsTriage milestone on Apr 25, 2022
  4. added
    P3
    on May 16, 2022
  5. modified the milestones: needsTriage, Backlog on May 16, 2022
  6. added a commit that references this issue on Jun 13, 2022
    3fd8948
  7. angular-automatic-lock-bot commented on Jul 14, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: corebug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions