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

ng g module my-module only generates the module.ts file

Open vlrprbttst opened this issue 9 years ago • 10 comments

i'm just starting with angular and i was following a beginner screencast tutorial. when the guy creates a new module: https://youtu.be/fXHyqSIIF9Q?t=14m10s angular-cli spits css/html/component files as you can see, but on my local environment all i get is the xxx.module.ts file. and this warning:

WARNING Module is generated but not provided, it must be provided to be used

is there something wrong or is it an old screencast?

sorry for the very noob question. just moving my very first steps here

vlrprbttst avatar Jun 29 '17 17:06 vlrprbttst

As per issue #3365 and PR #3389 this has changed to have only module generated by default.

But with the --routing flag it should generate the component as per generate-module.spec.js

it('ng generate module  generate routing and component files when passed flag --routing', 
function () {}

and e2e/tests/generate/module/module-routing.ts

I have tried it and generate is not creating the component or the spec with --routing flag. I am not sure if I am missing something or if this is a regression. Doc's say nothing about the routing flag though.

Module not provided is just a warning. You can specify --module=, eg: --module=app to import the newly created module to an existing module to get rid of those warning.

rageshvr avatar Jun 29 '17 20:06 rageshvr

Since new version is out: I had verified this in version 1.1.3

rageshvr avatar Jun 29 '17 21:06 rageshvr

is it an old screencast?

video is from Oct 5, 2016

First stable release Mar 24 2017: https://github.com/angular/angular-cli/releases/tag/v1.0.0

Please refer to the docs: https://github.com/angular/angular-cli/wiki

tytskyi avatar Jun 29 '17 21:06 tytskyi

is it an old screencast?

Yep it is :smiley. I'm the author of the screencast and I created it now nearly 10 months ago. While the shown Angular techniques are still valid, the CLI has changed its behavior in some cases such as in this one.

So while before it generated the module and some sample components as well, now you have to do it separately in two steps:

$ ng g module people

and then generate the component

$ ng g component people/people

which generates a people.component.ts in the module people, therefore the people/people.

Also take a look at the docs, they're quite good now:

Hope that helps, otherwise simply ping me again if you have any further questions :wink:

juristr avatar Jun 30 '17 06:06 juristr

Can confirm in 1.2.0, ng generate module --routing not creating component.

@angular/cli: 1.2.0
node: 8.1.3
os: win32 x64
@angular/animations: 4.2.5
@angular/common: 4.2.5
@angular/compiler: 4.2.5
@angular/core: 4.2.5
@angular/forms: 4.2.5
@angular/http: 4.2.5
@angular/platform-browser: 4.2.5
@angular/platform-browser-dynamic: 4.2.5
@angular/router: 4.2.5
@angular/cli: 1.2.0
@angular/compiler-cli: 4.2.5
@angular/language-service: 4.2.5
ng new my-app
cd my-app
ng g m my-module --routing
create src\app\my-module\my-module-routing.module.ts
  create src\app\my-module\my-module.module.ts
  WARNING Module is generated but not provided, it must be provided to be used

Can someone please confirm, if --routing flag can be used to create module along with component?

rageshvr avatar Jun 30 '17 07:06 rageshvr

@rageshvr --routing is for creating routing information. See the docs

Just as a hint, you can also add --dry-run to just check which files would be created by the CLI without any effect on your file system.

juristr avatar Jun 30 '17 09:06 juristr

Yeah my bad, I interpreted it wrong. It create only route with that flag.

rageshvr avatar Jun 30 '17 10:06 rageshvr

@vlrprbttst I think this issue can be closed, right? //cc @rageshvr

juristr avatar Jul 02 '17 06:07 juristr

Hi there!! Look at the default settings of module in schema.json(node_modules/@angular/cli/lib/config/schema.json) file. Change as required..

If module->properties->spec->default(find in below code) is false, it only generates module.ts. By default, it is false. If you want to generate module.spec.ts file, change it to true..

"module": { "description": "Options for generating a module.", "type": "object", "properties": { "flat": { "description": "Flag to indicate if a dir is created.", "type": "boolean", "default": false }, "spec": { "description": "Specifies if a spec file is generated.", "type": "boolean", "default": false } } }

Ranjita-M avatar May 15 '18 06:05 Ranjita-M

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.