Creating a component and adding it to an existing module.

Sometimes when creating a component, we want it to exist under a module to keep things structured and so that our app module doesn’t get huge. It can also provide other benefits like lazy module loading and some nice other features. So that others know, the important thing here is that the file name of the module is given, NOT the actual module name (sometimes they are different)

Otherwise, we could get errors saying that the module doesn’t exist.

For this command, I find it best to run it from the src directory of the angular application. You will see why in a tick!

Here is an example:

ng g c  thepathwhereyouwantthecomponent/thecomponentname -m pathtotheexistingmodule/theexistingmodulefilename.module.ts

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *