Hello I\'ve just created a new project from the CLI using the simple
ng new frontend
command however once I go into my project to:
Using Angular@7 ng g c
works from the root app folder. No need to change anything - just run from the base directory something like
ng g c features/shopping-list/components/shopping-list-edit
=>
CREATE src/app/features/shopping-list/components/shopping-list-edit/shopping-list-edit.component.ts (316 bytes)
Change root
to the directory where your module is in angular.json
From:
root:""
to directory of app module:
root: "/src/app"
Could not find ngModule can be solved by passing --module=<path to app.module.ts>
There are multiple ways to fix this issue one among them is as follows,
ng g c components/list-template --module=modules/app.module.ts
For other options with respect to generate component is here https://angular.io/cli/generate#component
The code for generating a component
and resolving closest NgModule
is quite straightforward. You can find it here https://github.com/angular/devkit/blob/master/packages/schematics/angular/component/index.ts [Note: link currently dead 15 June 2020]
It doesn't depend on the typescript, npm etc. version. Only on the @angular/cli version (and indirectly on the devkit) which in your case is the latest. All should be working fine; at least it does on my end.
you should run this command 'ng g c component-name' inside is app folder.
1) cd src/app 2) ng g c component name
In my case, the problem was in angular.json file. I had to remove all the 'projectname-e2e' project at the angular.json file for fix this issue.