Angular 2 CLI command "ng generate component" cannot find app.module

I am trying to generate new components using the Angular2 CLI tool with this command:

ng generate component test

After execution, new component files are created, but the links are not added to the app.module.ts file:

No application module found. Add your new class to your component.

enter image description here

I tried to find a solution to fix this, so I did not need to always import a new component and add it to the ads manually, but I could not find anything about this problem on the Internet.

I think this may have something to do with my angular-cli.json file, but it seems like this is normal: enter image description here

Any ideas?

UPDATE: This is my project folder structure, simple. I deleted folders that do not matter:

enter image description here

The code in app.module.ts is as follows:

import { NgModule }         from '@angular/core';
import { BrowserModule }    from '@angular/platform-browser';
import { HttpModule }       from '@angular/http';
import { AppComponent }     from './app.component';
import { SearchComponent }  from './search/search.component';

@
NgModule({
    declarations: [
        AppComponent,
        SearchComponent
    ],
    imports: [
        BrowserModule,
        HttpModule
    ],
    providers: [
    ],
    bootstrap: [
        AppComponent
    ]
})
export class AppModule { }
+4
2

, angular-cli , , "@" "NgModule" . , CLI :

@
NgModule({

, cli :

@NgModule({
+1

. . app.module.ts.

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 { HeaderComponent } from './header/header.component';<!-- My Installed Component -->
import { FooterComponent } from './footer/footer.component';<!-- My Installed Component -->

@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,<!-- My Installed Component -->
    FooterComponent<!-- My Installed Component -->
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
0

Source: https://habr.com/ru/post/1661483/


All Articles