Angular-cli: Command `ng generate component` incorrectly append a component in app.module.ts

Created on 17 Nov 2017  路  5Comments  路  Source: angular/angular-cli

Versions

Angular CLI: 1.5.0
Node: 8.9.1
OS: win32 x64
Angular: 5.0.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.5.0
@angular-devkit/build-optimizer: 0.0.33
@angular-devkit/core: 0.0.20
@angular-devkit/schematics: 0.0.35
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.3
typescript: 2.4.2
webpack: 3.8.1

Repro steps

  • write ng g component content/bar

Observed behavior

This bug appear when I write command ng g component, angular-cli append component to declarations incorrectly, because I use an indent to view the hierarchy of components:

@NgModule({
  declarations: [
    // Directives
    FooDirective,
    BarDirective,
    // Pipes
    FooPipe,
    BarPipe,
    // Components
    AppComponent,
      ContentComponent,
        FooComponent,
          BazzComponent,
          ,
          BarComponentBazComponent,
  ],
  imports: [
    <...>
  ],
  providers: [
    <...>
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

or it can be so:

@NgModule({
  declarations: [
    // Directives
    FooDirective,
    BarDirective,
    // Pipes
    FooPipe,
    BarPipe,
    // Components
    AppComponent,
      ContentComponent,
        FooComponent,
          BazzComponent,
          BazCompone,
          BarComponentnt,
  ],
  imports: [
    <...>
  ],
  providers: [
    <...>
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Desired behavior

I need correctly to append components to the declarations.

Mention any other details that might be useful

In version 1.3.2, everything worked correctly, but in version 1.5.0 I should correct bug result every times. Please fix this bug!

investigation bufix

Most helpful comment

I'm also having the same issue as @hahn-kev in version 1.6. In addition to the import statment appending the last 2 characters of the previous line to the next import statement, I'm also having the same issue with the same generated components declarations statement within that module file.

declarations: [ DashboardCompone, TestComponentnt ],

All 5 comments

@Brocco seems like this is similar to the pos vs getStart() problem we had in imports? Maybe not.

I've got this same issue, though I'm not doing any special indenting. I also have a similar issue with imports where it's taking the last 2 characters of the line and putting them on the end of the new line, like so:

import { PersonService } from './people/person.servic;
import { RoleComponent } from './people/person/role.component'e';

(e' on line 2 should be at the end of line 1)

I'm also having the same issue as @hahn-kev in version 1.6. In addition to the import statment appending the last 2 characters of the previous line to the next import statement, I'm also having the same issue with the same generated components declarations statement within that module file.

declarations: [ DashboardCompone, TestComponentnt ],

Having the same issue as @jd21daugherty and @hahn-kev !

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zpydee picture zpydee  路  102Comments

bjornharvold picture bjornharvold  路  172Comments

adwd picture adwd  路  173Comments

rilwans picture rilwans  路  108Comments

Maistho picture Maistho  路  140Comments