angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

feature request(ng g c): add option to include generated component in module exports list

Open rxjs-space opened this issue 9 years ago • 3 comments

Please consider add following feature option when generating a component:
With a option, say --add-to-exports, we can run ng g c parent/shall-be-exported --add-to-exports, and get shallBeExportedComponent in the exports list of parentModule.

rxjs-space avatar Dec 29 '16 08:12 rxjs-space

I tried to give this a go but came across this:

blueprints/component/index.js

// ...

    if(options.export) {
      returns.push(
        astUtils.addExportToModule(this.pathToModule, className, importPath)
          .then(change => change.apply(NodeHost)));
    }

ast-utils.ts

export function addExportToModule(modulePath: string, classifiedName: string,
                                  importPath: string): Promise<Change> {
  return _addSymbolToNgModuleMetadata(modulePath, 'exports', classifiedName, importPath);
}

generates:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { CompTestComponent } from './comp-test/comp-test.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent],
  exports: [CompTestComponent]
})
export class AppModule { }

As you can see CompTestComponent is being added to the exports list, but it's not being declared.

baruchvlz avatar Dec 31 '16 14:12 baruchvlz

@baruchvlz thanks for taking a look, I'm about to start implementing this, I will keep you posted.

Brocco avatar Dec 31 '16 15:12 Brocco

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.