Skip to content

Support forwardRef() in NgModule.declarations #41801

Closed

Description

@pauldraper

🚀 feature request

Relevant Package

@angular/core

Description

Angular imports winds up very scattered.

import { Component, NgModule } from '@angular/core'; 
import { Other1Module } from './other-1';
import { Other2Module } from './other-2';
import { Other3Module } from './other-3';

@Component({
 ​selector: 'my',
 ​template: `
  ​<!-- ...100 line template... -->
​`
})
export class MyComponent {
  // 100 line component
}

@NgModule({
  declarations: [MyComponent],
  exports: [MyComponent],
  imports: [Other1Module, Other2Module, Other3Module]
export class MyModule {
}

In summary,

// import TS modules

// call component, directives, and pipes

// component code

// import NgModules

This makes it very hard to see what modules are being used, and removed unused NgModules. Especially since no one has developed tools remove unused NgModules (whereas that is prevalent with JSX).

The better organization would be

// import TS modules

// import NgModules

// call component, directives, and pipes 

// component code

That way, the hardest import code to follow (Angular templates/NgModules) is at least close together.

But that isn't possible because NgModule must come after the component it declares.

Describe the solution you'd like

I'd like forwardRef() to work with NgModules.declares, so I can put it before the Components, Directives, and Pipes.

Describe alternatives you've considered

Suffering through extraneous imports and poor tree shaking.

Activity

  1. JoostK commented on Apr 25, 2021

    @JoostK
    Member

    Did you try using forwardRef in NgModule.declarations? I believe it already works.

  2. Airblader commented on Apr 25, 2021

    @Airblader
    Contributor

    Somewhat related #41028 based on the description.

  3. pauldraper commented on Apr 25, 2021

    @pauldraper
    ContributorAuthor

    @JoostK I did, but apparently it was just transient StackBlitz funniness :/

    I tried again and it works.

    Thanks!

  4. angular-automatic-lock-bot commented on May 26, 2021

    @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.

  5. locked and limited conversation to collaborators on May 26, 2021
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions