Create component to specific module with Angular-CLI












88















I'm starting to use angular-cli and I've already read a lot to find an answer about what I want to do...no success, so I came here.



Is there a way to create a component to a new module?



e.g.: ng g module newModule



ng g component newComponent (how to add this component to newModule??)



because the angular-cli default behavior is to put all new components inside app.module. I would like to choose where my component will be, so that I can create separated modules and won't have all my components inside app.module . It is possible to do that using angular-cli or do I have to do this manually?










share|improve this question





























    88















    I'm starting to use angular-cli and I've already read a lot to find an answer about what I want to do...no success, so I came here.



    Is there a way to create a component to a new module?



    e.g.: ng g module newModule



    ng g component newComponent (how to add this component to newModule??)



    because the angular-cli default behavior is to put all new components inside app.module. I would like to choose where my component will be, so that I can create separated modules and won't have all my components inside app.module . It is possible to do that using angular-cli or do I have to do this manually?










    share|improve this question



























      88












      88








      88


      16






      I'm starting to use angular-cli and I've already read a lot to find an answer about what I want to do...no success, so I came here.



      Is there a way to create a component to a new module?



      e.g.: ng g module newModule



      ng g component newComponent (how to add this component to newModule??)



      because the angular-cli default behavior is to put all new components inside app.module. I would like to choose where my component will be, so that I can create separated modules and won't have all my components inside app.module . It is possible to do that using angular-cli or do I have to do this manually?










      share|improve this question
















      I'm starting to use angular-cli and I've already read a lot to find an answer about what I want to do...no success, so I came here.



      Is there a way to create a component to a new module?



      e.g.: ng g module newModule



      ng g component newComponent (how to add this component to newModule??)



      because the angular-cli default behavior is to put all new components inside app.module. I would like to choose where my component will be, so that I can create separated modules and won't have all my components inside app.module . It is possible to do that using angular-cli or do I have to do this manually?







      angular typescript angular-cli






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 11 '18 at 7:35









      RajnishCoder

      5812727




      5812727










      asked Nov 17 '16 at 8:20









      Elmer DantasElmer Dantas

      1,84921725




      1,84921725
























          14 Answers
          14






          active

          oldest

          votes


















          117














          To create a component as part of a module you should





          1. ng g module newModule to generate a module,


          2. cd newModule to change directory into the newModule folder


          3. ng g component newComponent to create a component as a child of the module.






          share|improve this answer





















          • 2





            That's exactly what was looking for. Thanks @Alexander. I think they should put this in Docs.

            – Elmer Dantas
            Nov 17 '16 at 8:34








          • 60





            You can also stay in the project root and prefix the component with the module name ng g component moduleName/componentName.

            – JayChase
            Nov 17 '16 at 12:53






          • 1





            With Angular CLI version 1.6.8, I was always getting error sying that 'specified module doesn't exists', when I sepcify an existing module. It worked when I tried the following command: ng generate service service1 --module=module1/module1.module.ts. Note: my service name is service1 and my module name is module1

            – Diallo
            Feb 11 '18 at 17:58













          • @JayChase's answer is the better option

            – shteeven
            Mar 13 '18 at 16:07






          • 1





            outdated as of 6th Oct, Angular 6

            – tom87416
            Oct 6 '18 at 7:57



















          63














          ng g component nameComponent --module=app.module.ts





          share|improve this answer


























          • the other answers work, but this is the most efficient. Its worth adding --dry-run to the end of that just to see what will be affected, it's a nice sanity check

            – tony09uk
            Dec 12 '18 at 21:55





















          57














          Not sure if maybe Alexander Ciesielski's answer was correct at the time of writing, but I can verify that this no longer works. It doesn't matter which directory in the project you run the Angular CLI. If you type



          ng g component newComponent


          it will generate a component and import it into the app.module.ts file



          The only way you can use CLI to automatically import it into another module is by specifying



          ng g component moduleName/newComponent


          where moduleName is a module you've already defined in your project. If the moduleName doesn't exist, it'll put the component in moduleName/newComponent directory but still import it into app.module






          share|improve this answer



















          • 2





            it was the right answer for me at the time..it works properly. I create a pull request to add this information to the docs. One of it's contributors ask me to remove cd-ing part..in the end will be 1. ng g module newModule 2. ng g component new-module/newComponent according to him should be new-module instead of newModule

            – Elmer Dantas
            Jan 31 '17 at 13:23













          • Just to point out, using technique by Alexander Ciesielski and works as expected. I should note, I did not need to create component simply needed to create folder. So I just mkdir a folder, and then ran n g component newComponent inside of newly created folder.

            – Master-Chief
            Apr 23 '17 at 3:10








          • 2





            I would say that full answer is ng g component moduleName/newComponent -m moduleName

            – slavugan
            Jul 26 '17 at 9:09













          • In my case the component name is same as the module name so I created the module with ng generate module {modComName} 1) Created the folder 2) Created a module file inside the folder of same name ; the command ng generate component {modComName} actually 1) Created a component file inside the folder of same name 2) Modified the module to import the component

            – The Red Pea
            May 27 '18 at 14:36











          • Be careful if you create a module and import it into a base module; ng adds imports to the end of the array; but you may want : "The order of the routes in the configuration matters and this is by design."

            – The Red Pea
            May 27 '18 at 14:59



















          20














          I didn't find an answer that showed how to use the cli to generate a component inside a top level module folder, and also have the component automatically added the the module's declaration collection.



          To create the module run this:



          ng g module foo


          To create the component inside the foo module folder and have it added to the foo.module.ts's declaration collection run this:



          ng g component foo/fooList --module=foo.module.ts


          And the cli will scaffold out the module and component like this:



          enter image description here



          --EDIT the new version of the angular cli behaves differently. 1.5.5 doesn't want a module file name so the command with v1.5.5 should be



          ng g component foo/fooList --module=foo





          share|improve this answer


























          • Yay for the --module argument; the docs say "Allows specification of the declaring module." ; I would add --module specifies which existing module should be modified to import the module you are about to create

            – The Red Pea
            May 27 '18 at 14:27








          • 1





            @TheRedPea I believe you meant to say " --module specifies which existing module should be modified to import the component you are ..."

            – cobolstinks
            Jul 3 '18 at 14:14











          • Yep you're right! Existing module modified with reference to new component

            – The Red Pea
            Jul 3 '18 at 17:04



















          9














          You can try below command, which describes the,



          ng -> Angular 
          g -> Generate
          c -> Component
          -m -> Module


          Then your command will be like:



          ng g c user/userComponent -m user.module





          share|improve this answer

































            6














            this is what worked for me :



            1 -->  ng g module new-module

            2 --> ng g c new-module/component-test --module=new-module/new-module.module.ts


            If you want to generate a component without its directory use --flat flag.






            share|improve this answer
























            • don't need to write .ts

              – Lapenkov Vladimir
              Jun 30 '18 at 7:10











            • --module=path-to-module worked form me thanks @Mohamed Makkaoui

              – Ian Poston Framer
              Sep 18 '18 at 6:24











            • you're welcome @IanPostonFramer

              – Mohamed Makkaoui
              Sep 18 '18 at 11:13



















            4














            For Angular v4 and Above, simply use:



            ng g c componentName -m ModuleName





            share|improve this answer





















            • 1





              Throws an error Specified module does not exist whereas module existed

              – Pardeep Jain
              May 28 '18 at 10:20






            • 1





              You don't specify the name of the module, you specify the module's filename.

              – Roger
              Jun 6 '18 at 8:46



















            1














            Use this simple command:



            ng g c users/userlist


            users: Your module name.



            userlist: Your component name.






            share|improve this answer

































              1














              According to Angular docs the way to create a component for specific module is,



              ng g component <directory name>/<component name>


              "directory name" = where the CLI generated the feature module



              Example :-



              ng generate component customer-dashboard/CustomerDashboard


              This generates a folder for the new component within the customer-dashboard folder and updates the feature module with the CustomerDashboardComponent






              share|improve this answer































                0














                Add a component to the Angular 4 app using Angular CLI



                To add a new Angular 4 component to the app, use command ng g component componentName. After execution of this command, Angular CLI adds a folder component-name under srcapp. Also, the references of the same is added to srcappapp.module.ts file automatically.



                A component shall have a @Component decorator function followed by a class which needs to be exported. The @Component decorator function accepts meta data.



                Add a component to specific folder of the Angular 4 app using Angular CLI



                To add a new component to a specific folder use the command ng g component folderName/componentName






                share|improve this answer































                  0














                  I am having the similar issues with multiple modules in application. A component can be created to any module so before creating a component we have to specify the name of the particular module.



                  'ng generate component newCompName --module= specify name of module'





                  share|improve this answer































                    0














                    If you have multiple apps declared in .angular-cli.json ( e.g. in case working on feature module)



                    "apps": [{
                    "name": "app-name",
                    "root": "lib",
                    "appRoot": ""
                    }, {...} ]


                    You can :



                    ng g c my-comp -a app-name


                    -a stands for --app (name)






                    share|improve this answer































                      0














                      First run ng g module newModule
                      . Then run ng g component newModule/newModule --flat






                      share|improve this answer































                        0














                        I am currently working on angular 5 projects and I use this particular command for generating components inside a module.



                        ng g c <module-name>/<new-component-name>


                        This command will generate component local to the module if you use normal command eg



                        ng g c <component-name>


                        it will generate component inside the app module a.k.a root module.



                        Note: code enclosed in <> represent user specific names.






                        share|improve this answer























                          Your Answer






                          StackExchange.ifUsing("editor", function () {
                          StackExchange.using("externalEditor", function () {
                          StackExchange.using("snippets", function () {
                          StackExchange.snippets.init();
                          });
                          });
                          }, "code-snippets");

                          StackExchange.ready(function() {
                          var channelOptions = {
                          tags: "".split(" "),
                          id: "1"
                          };
                          initTagRenderer("".split(" "), "".split(" "), channelOptions);

                          StackExchange.using("externalEditor", function() {
                          // Have to fire editor after snippets, if snippets enabled
                          if (StackExchange.settings.snippets.snippetsEnabled) {
                          StackExchange.using("snippets", function() {
                          createEditor();
                          });
                          }
                          else {
                          createEditor();
                          }
                          });

                          function createEditor() {
                          StackExchange.prepareEditor({
                          heartbeatType: 'answer',
                          autoActivateHeartbeat: false,
                          convertImagesToLinks: true,
                          noModals: true,
                          showLowRepImageUploadWarning: true,
                          reputationToPostImages: 10,
                          bindNavPrevention: true,
                          postfix: "",
                          imageUploader: {
                          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                          allowUrls: true
                          },
                          onDemand: true,
                          discardSelector: ".discard-answer"
                          ,immediatelyShowMarkdownHelp:true
                          });


                          }
                          });














                          draft saved

                          draft discarded


















                          StackExchange.ready(
                          function () {
                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40649799%2fcreate-component-to-specific-module-with-angular-cli%23new-answer', 'question_page');
                          }
                          );

                          Post as a guest















                          Required, but never shown

























                          14 Answers
                          14






                          active

                          oldest

                          votes








                          14 Answers
                          14






                          active

                          oldest

                          votes









                          active

                          oldest

                          votes






                          active

                          oldest

                          votes









                          117














                          To create a component as part of a module you should





                          1. ng g module newModule to generate a module,


                          2. cd newModule to change directory into the newModule folder


                          3. ng g component newComponent to create a component as a child of the module.






                          share|improve this answer





















                          • 2





                            That's exactly what was looking for. Thanks @Alexander. I think they should put this in Docs.

                            – Elmer Dantas
                            Nov 17 '16 at 8:34








                          • 60





                            You can also stay in the project root and prefix the component with the module name ng g component moduleName/componentName.

                            – JayChase
                            Nov 17 '16 at 12:53






                          • 1





                            With Angular CLI version 1.6.8, I was always getting error sying that 'specified module doesn't exists', when I sepcify an existing module. It worked when I tried the following command: ng generate service service1 --module=module1/module1.module.ts. Note: my service name is service1 and my module name is module1

                            – Diallo
                            Feb 11 '18 at 17:58













                          • @JayChase's answer is the better option

                            – shteeven
                            Mar 13 '18 at 16:07






                          • 1





                            outdated as of 6th Oct, Angular 6

                            – tom87416
                            Oct 6 '18 at 7:57
















                          117














                          To create a component as part of a module you should





                          1. ng g module newModule to generate a module,


                          2. cd newModule to change directory into the newModule folder


                          3. ng g component newComponent to create a component as a child of the module.






                          share|improve this answer





















                          • 2





                            That's exactly what was looking for. Thanks @Alexander. I think they should put this in Docs.

                            – Elmer Dantas
                            Nov 17 '16 at 8:34








                          • 60





                            You can also stay in the project root and prefix the component with the module name ng g component moduleName/componentName.

                            – JayChase
                            Nov 17 '16 at 12:53






                          • 1





                            With Angular CLI version 1.6.8, I was always getting error sying that 'specified module doesn't exists', when I sepcify an existing module. It worked when I tried the following command: ng generate service service1 --module=module1/module1.module.ts. Note: my service name is service1 and my module name is module1

                            – Diallo
                            Feb 11 '18 at 17:58













                          • @JayChase's answer is the better option

                            – shteeven
                            Mar 13 '18 at 16:07






                          • 1





                            outdated as of 6th Oct, Angular 6

                            – tom87416
                            Oct 6 '18 at 7:57














                          117












                          117








                          117







                          To create a component as part of a module you should





                          1. ng g module newModule to generate a module,


                          2. cd newModule to change directory into the newModule folder


                          3. ng g component newComponent to create a component as a child of the module.






                          share|improve this answer















                          To create a component as part of a module you should





                          1. ng g module newModule to generate a module,


                          2. cd newModule to change directory into the newModule folder


                          3. ng g component newComponent to create a component as a child of the module.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 12 '16 at 13:48

























                          answered Nov 17 '16 at 8:22









                          Alexander CiesielskiAlexander Ciesielski

                          6,12633057




                          6,12633057








                          • 2





                            That's exactly what was looking for. Thanks @Alexander. I think they should put this in Docs.

                            – Elmer Dantas
                            Nov 17 '16 at 8:34








                          • 60





                            You can also stay in the project root and prefix the component with the module name ng g component moduleName/componentName.

                            – JayChase
                            Nov 17 '16 at 12:53






                          • 1





                            With Angular CLI version 1.6.8, I was always getting error sying that 'specified module doesn't exists', when I sepcify an existing module. It worked when I tried the following command: ng generate service service1 --module=module1/module1.module.ts. Note: my service name is service1 and my module name is module1

                            – Diallo
                            Feb 11 '18 at 17:58













                          • @JayChase's answer is the better option

                            – shteeven
                            Mar 13 '18 at 16:07






                          • 1





                            outdated as of 6th Oct, Angular 6

                            – tom87416
                            Oct 6 '18 at 7:57














                          • 2





                            That's exactly what was looking for. Thanks @Alexander. I think they should put this in Docs.

                            – Elmer Dantas
                            Nov 17 '16 at 8:34








                          • 60





                            You can also stay in the project root and prefix the component with the module name ng g component moduleName/componentName.

                            – JayChase
                            Nov 17 '16 at 12:53






                          • 1





                            With Angular CLI version 1.6.8, I was always getting error sying that 'specified module doesn't exists', when I sepcify an existing module. It worked when I tried the following command: ng generate service service1 --module=module1/module1.module.ts. Note: my service name is service1 and my module name is module1

                            – Diallo
                            Feb 11 '18 at 17:58













                          • @JayChase's answer is the better option

                            – shteeven
                            Mar 13 '18 at 16:07






                          • 1





                            outdated as of 6th Oct, Angular 6

                            – tom87416
                            Oct 6 '18 at 7:57








                          2




                          2





                          That's exactly what was looking for. Thanks @Alexander. I think they should put this in Docs.

                          – Elmer Dantas
                          Nov 17 '16 at 8:34







                          That's exactly what was looking for. Thanks @Alexander. I think they should put this in Docs.

                          – Elmer Dantas
                          Nov 17 '16 at 8:34






                          60




                          60





                          You can also stay in the project root and prefix the component with the module name ng g component moduleName/componentName.

                          – JayChase
                          Nov 17 '16 at 12:53





                          You can also stay in the project root and prefix the component with the module name ng g component moduleName/componentName.

                          – JayChase
                          Nov 17 '16 at 12:53




                          1




                          1





                          With Angular CLI version 1.6.8, I was always getting error sying that 'specified module doesn't exists', when I sepcify an existing module. It worked when I tried the following command: ng generate service service1 --module=module1/module1.module.ts. Note: my service name is service1 and my module name is module1

                          – Diallo
                          Feb 11 '18 at 17:58







                          With Angular CLI version 1.6.8, I was always getting error sying that 'specified module doesn't exists', when I sepcify an existing module. It worked when I tried the following command: ng generate service service1 --module=module1/module1.module.ts. Note: my service name is service1 and my module name is module1

                          – Diallo
                          Feb 11 '18 at 17:58















                          @JayChase's answer is the better option

                          – shteeven
                          Mar 13 '18 at 16:07





                          @JayChase's answer is the better option

                          – shteeven
                          Mar 13 '18 at 16:07




                          1




                          1





                          outdated as of 6th Oct, Angular 6

                          – tom87416
                          Oct 6 '18 at 7:57





                          outdated as of 6th Oct, Angular 6

                          – tom87416
                          Oct 6 '18 at 7:57













                          63














                          ng g component nameComponent --module=app.module.ts





                          share|improve this answer


























                          • the other answers work, but this is the most efficient. Its worth adding --dry-run to the end of that just to see what will be affected, it's a nice sanity check

                            – tony09uk
                            Dec 12 '18 at 21:55


















                          63














                          ng g component nameComponent --module=app.module.ts





                          share|improve this answer


























                          • the other answers work, but this is the most efficient. Its worth adding --dry-run to the end of that just to see what will be affected, it's a nice sanity check

                            – tony09uk
                            Dec 12 '18 at 21:55
















                          63












                          63








                          63







                          ng g component nameComponent --module=app.module.ts





                          share|improve this answer















                          ng g component nameComponent --module=app.module.ts






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jun 28 '17 at 20:50









                          JNYRanger

                          4,64093561




                          4,64093561










                          answered Jun 28 '17 at 20:30









                          Daniel Fernando Acosta CeballoDaniel Fernando Acosta Ceballo

                          72955




                          72955













                          • the other answers work, but this is the most efficient. Its worth adding --dry-run to the end of that just to see what will be affected, it's a nice sanity check

                            – tony09uk
                            Dec 12 '18 at 21:55





















                          • the other answers work, but this is the most efficient. Its worth adding --dry-run to the end of that just to see what will be affected, it's a nice sanity check

                            – tony09uk
                            Dec 12 '18 at 21:55



















                          the other answers work, but this is the most efficient. Its worth adding --dry-run to the end of that just to see what will be affected, it's a nice sanity check

                          – tony09uk
                          Dec 12 '18 at 21:55







                          the other answers work, but this is the most efficient. Its worth adding --dry-run to the end of that just to see what will be affected, it's a nice sanity check

                          – tony09uk
                          Dec 12 '18 at 21:55













                          57














                          Not sure if maybe Alexander Ciesielski's answer was correct at the time of writing, but I can verify that this no longer works. It doesn't matter which directory in the project you run the Angular CLI. If you type



                          ng g component newComponent


                          it will generate a component and import it into the app.module.ts file



                          The only way you can use CLI to automatically import it into another module is by specifying



                          ng g component moduleName/newComponent


                          where moduleName is a module you've already defined in your project. If the moduleName doesn't exist, it'll put the component in moduleName/newComponent directory but still import it into app.module






                          share|improve this answer



















                          • 2





                            it was the right answer for me at the time..it works properly. I create a pull request to add this information to the docs. One of it's contributors ask me to remove cd-ing part..in the end will be 1. ng g module newModule 2. ng g component new-module/newComponent according to him should be new-module instead of newModule

                            – Elmer Dantas
                            Jan 31 '17 at 13:23













                          • Just to point out, using technique by Alexander Ciesielski and works as expected. I should note, I did not need to create component simply needed to create folder. So I just mkdir a folder, and then ran n g component newComponent inside of newly created folder.

                            – Master-Chief
                            Apr 23 '17 at 3:10








                          • 2





                            I would say that full answer is ng g component moduleName/newComponent -m moduleName

                            – slavugan
                            Jul 26 '17 at 9:09













                          • In my case the component name is same as the module name so I created the module with ng generate module {modComName} 1) Created the folder 2) Created a module file inside the folder of same name ; the command ng generate component {modComName} actually 1) Created a component file inside the folder of same name 2) Modified the module to import the component

                            – The Red Pea
                            May 27 '18 at 14:36











                          • Be careful if you create a module and import it into a base module; ng adds imports to the end of the array; but you may want : "The order of the routes in the configuration matters and this is by design."

                            – The Red Pea
                            May 27 '18 at 14:59
















                          57














                          Not sure if maybe Alexander Ciesielski's answer was correct at the time of writing, but I can verify that this no longer works. It doesn't matter which directory in the project you run the Angular CLI. If you type



                          ng g component newComponent


                          it will generate a component and import it into the app.module.ts file



                          The only way you can use CLI to automatically import it into another module is by specifying



                          ng g component moduleName/newComponent


                          where moduleName is a module you've already defined in your project. If the moduleName doesn't exist, it'll put the component in moduleName/newComponent directory but still import it into app.module






                          share|improve this answer



















                          • 2





                            it was the right answer for me at the time..it works properly. I create a pull request to add this information to the docs. One of it's contributors ask me to remove cd-ing part..in the end will be 1. ng g module newModule 2. ng g component new-module/newComponent according to him should be new-module instead of newModule

                            – Elmer Dantas
                            Jan 31 '17 at 13:23













                          • Just to point out, using technique by Alexander Ciesielski and works as expected. I should note, I did not need to create component simply needed to create folder. So I just mkdir a folder, and then ran n g component newComponent inside of newly created folder.

                            – Master-Chief
                            Apr 23 '17 at 3:10








                          • 2





                            I would say that full answer is ng g component moduleName/newComponent -m moduleName

                            – slavugan
                            Jul 26 '17 at 9:09













                          • In my case the component name is same as the module name so I created the module with ng generate module {modComName} 1) Created the folder 2) Created a module file inside the folder of same name ; the command ng generate component {modComName} actually 1) Created a component file inside the folder of same name 2) Modified the module to import the component

                            – The Red Pea
                            May 27 '18 at 14:36











                          • Be careful if you create a module and import it into a base module; ng adds imports to the end of the array; but you may want : "The order of the routes in the configuration matters and this is by design."

                            – The Red Pea
                            May 27 '18 at 14:59














                          57












                          57








                          57







                          Not sure if maybe Alexander Ciesielski's answer was correct at the time of writing, but I can verify that this no longer works. It doesn't matter which directory in the project you run the Angular CLI. If you type



                          ng g component newComponent


                          it will generate a component and import it into the app.module.ts file



                          The only way you can use CLI to automatically import it into another module is by specifying



                          ng g component moduleName/newComponent


                          where moduleName is a module you've already defined in your project. If the moduleName doesn't exist, it'll put the component in moduleName/newComponent directory but still import it into app.module






                          share|improve this answer













                          Not sure if maybe Alexander Ciesielski's answer was correct at the time of writing, but I can verify that this no longer works. It doesn't matter which directory in the project you run the Angular CLI. If you type



                          ng g component newComponent


                          it will generate a component and import it into the app.module.ts file



                          The only way you can use CLI to automatically import it into another module is by specifying



                          ng g component moduleName/newComponent


                          where moduleName is a module you've already defined in your project. If the moduleName doesn't exist, it'll put the component in moduleName/newComponent directory but still import it into app.module







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 31 '17 at 12:16









                          DiskdriveDiskdrive

                          6,5772175129




                          6,5772175129








                          • 2





                            it was the right answer for me at the time..it works properly. I create a pull request to add this information to the docs. One of it's contributors ask me to remove cd-ing part..in the end will be 1. ng g module newModule 2. ng g component new-module/newComponent according to him should be new-module instead of newModule

                            – Elmer Dantas
                            Jan 31 '17 at 13:23













                          • Just to point out, using technique by Alexander Ciesielski and works as expected. I should note, I did not need to create component simply needed to create folder. So I just mkdir a folder, and then ran n g component newComponent inside of newly created folder.

                            – Master-Chief
                            Apr 23 '17 at 3:10








                          • 2





                            I would say that full answer is ng g component moduleName/newComponent -m moduleName

                            – slavugan
                            Jul 26 '17 at 9:09













                          • In my case the component name is same as the module name so I created the module with ng generate module {modComName} 1) Created the folder 2) Created a module file inside the folder of same name ; the command ng generate component {modComName} actually 1) Created a component file inside the folder of same name 2) Modified the module to import the component

                            – The Red Pea
                            May 27 '18 at 14:36











                          • Be careful if you create a module and import it into a base module; ng adds imports to the end of the array; but you may want : "The order of the routes in the configuration matters and this is by design."

                            – The Red Pea
                            May 27 '18 at 14:59














                          • 2





                            it was the right answer for me at the time..it works properly. I create a pull request to add this information to the docs. One of it's contributors ask me to remove cd-ing part..in the end will be 1. ng g module newModule 2. ng g component new-module/newComponent according to him should be new-module instead of newModule

                            – Elmer Dantas
                            Jan 31 '17 at 13:23













                          • Just to point out, using technique by Alexander Ciesielski and works as expected. I should note, I did not need to create component simply needed to create folder. So I just mkdir a folder, and then ran n g component newComponent inside of newly created folder.

                            – Master-Chief
                            Apr 23 '17 at 3:10








                          • 2





                            I would say that full answer is ng g component moduleName/newComponent -m moduleName

                            – slavugan
                            Jul 26 '17 at 9:09













                          • In my case the component name is same as the module name so I created the module with ng generate module {modComName} 1) Created the folder 2) Created a module file inside the folder of same name ; the command ng generate component {modComName} actually 1) Created a component file inside the folder of same name 2) Modified the module to import the component

                            – The Red Pea
                            May 27 '18 at 14:36











                          • Be careful if you create a module and import it into a base module; ng adds imports to the end of the array; but you may want : "The order of the routes in the configuration matters and this is by design."

                            – The Red Pea
                            May 27 '18 at 14:59








                          2




                          2





                          it was the right answer for me at the time..it works properly. I create a pull request to add this information to the docs. One of it's contributors ask me to remove cd-ing part..in the end will be 1. ng g module newModule 2. ng g component new-module/newComponent according to him should be new-module instead of newModule

                          – Elmer Dantas
                          Jan 31 '17 at 13:23







                          it was the right answer for me at the time..it works properly. I create a pull request to add this information to the docs. One of it's contributors ask me to remove cd-ing part..in the end will be 1. ng g module newModule 2. ng g component new-module/newComponent according to him should be new-module instead of newModule

                          – Elmer Dantas
                          Jan 31 '17 at 13:23















                          Just to point out, using technique by Alexander Ciesielski and works as expected. I should note, I did not need to create component simply needed to create folder. So I just mkdir a folder, and then ran n g component newComponent inside of newly created folder.

                          – Master-Chief
                          Apr 23 '17 at 3:10







                          Just to point out, using technique by Alexander Ciesielski and works as expected. I should note, I did not need to create component simply needed to create folder. So I just mkdir a folder, and then ran n g component newComponent inside of newly created folder.

                          – Master-Chief
                          Apr 23 '17 at 3:10






                          2




                          2





                          I would say that full answer is ng g component moduleName/newComponent -m moduleName

                          – slavugan
                          Jul 26 '17 at 9:09







                          I would say that full answer is ng g component moduleName/newComponent -m moduleName

                          – slavugan
                          Jul 26 '17 at 9:09















                          In my case the component name is same as the module name so I created the module with ng generate module {modComName} 1) Created the folder 2) Created a module file inside the folder of same name ; the command ng generate component {modComName} actually 1) Created a component file inside the folder of same name 2) Modified the module to import the component

                          – The Red Pea
                          May 27 '18 at 14:36





                          In my case the component name is same as the module name so I created the module with ng generate module {modComName} 1) Created the folder 2) Created a module file inside the folder of same name ; the command ng generate component {modComName} actually 1) Created a component file inside the folder of same name 2) Modified the module to import the component

                          – The Red Pea
                          May 27 '18 at 14:36













                          Be careful if you create a module and import it into a base module; ng adds imports to the end of the array; but you may want : "The order of the routes in the configuration matters and this is by design."

                          – The Red Pea
                          May 27 '18 at 14:59





                          Be careful if you create a module and import it into a base module; ng adds imports to the end of the array; but you may want : "The order of the routes in the configuration matters and this is by design."

                          – The Red Pea
                          May 27 '18 at 14:59











                          20














                          I didn't find an answer that showed how to use the cli to generate a component inside a top level module folder, and also have the component automatically added the the module's declaration collection.



                          To create the module run this:



                          ng g module foo


                          To create the component inside the foo module folder and have it added to the foo.module.ts's declaration collection run this:



                          ng g component foo/fooList --module=foo.module.ts


                          And the cli will scaffold out the module and component like this:



                          enter image description here



                          --EDIT the new version of the angular cli behaves differently. 1.5.5 doesn't want a module file name so the command with v1.5.5 should be



                          ng g component foo/fooList --module=foo





                          share|improve this answer


























                          • Yay for the --module argument; the docs say "Allows specification of the declaring module." ; I would add --module specifies which existing module should be modified to import the module you are about to create

                            – The Red Pea
                            May 27 '18 at 14:27








                          • 1





                            @TheRedPea I believe you meant to say " --module specifies which existing module should be modified to import the component you are ..."

                            – cobolstinks
                            Jul 3 '18 at 14:14











                          • Yep you're right! Existing module modified with reference to new component

                            – The Red Pea
                            Jul 3 '18 at 17:04
















                          20














                          I didn't find an answer that showed how to use the cli to generate a component inside a top level module folder, and also have the component automatically added the the module's declaration collection.



                          To create the module run this:



                          ng g module foo


                          To create the component inside the foo module folder and have it added to the foo.module.ts's declaration collection run this:



                          ng g component foo/fooList --module=foo.module.ts


                          And the cli will scaffold out the module and component like this:



                          enter image description here



                          --EDIT the new version of the angular cli behaves differently. 1.5.5 doesn't want a module file name so the command with v1.5.5 should be



                          ng g component foo/fooList --module=foo





                          share|improve this answer


























                          • Yay for the --module argument; the docs say "Allows specification of the declaring module." ; I would add --module specifies which existing module should be modified to import the module you are about to create

                            – The Red Pea
                            May 27 '18 at 14:27








                          • 1





                            @TheRedPea I believe you meant to say " --module specifies which existing module should be modified to import the component you are ..."

                            – cobolstinks
                            Jul 3 '18 at 14:14











                          • Yep you're right! Existing module modified with reference to new component

                            – The Red Pea
                            Jul 3 '18 at 17:04














                          20












                          20








                          20







                          I didn't find an answer that showed how to use the cli to generate a component inside a top level module folder, and also have the component automatically added the the module's declaration collection.



                          To create the module run this:



                          ng g module foo


                          To create the component inside the foo module folder and have it added to the foo.module.ts's declaration collection run this:



                          ng g component foo/fooList --module=foo.module.ts


                          And the cli will scaffold out the module and component like this:



                          enter image description here



                          --EDIT the new version of the angular cli behaves differently. 1.5.5 doesn't want a module file name so the command with v1.5.5 should be



                          ng g component foo/fooList --module=foo





                          share|improve this answer















                          I didn't find an answer that showed how to use the cli to generate a component inside a top level module folder, and also have the component automatically added the the module's declaration collection.



                          To create the module run this:



                          ng g module foo


                          To create the component inside the foo module folder and have it added to the foo.module.ts's declaration collection run this:



                          ng g component foo/fooList --module=foo.module.ts


                          And the cli will scaffold out the module and component like this:



                          enter image description here



                          --EDIT the new version of the angular cli behaves differently. 1.5.5 doesn't want a module file name so the command with v1.5.5 should be



                          ng g component foo/fooList --module=foo






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 15 '17 at 17:53

























                          answered Aug 4 '17 at 14:19









                          cobolstinkscobolstinks

                          2,38393861




                          2,38393861













                          • Yay for the --module argument; the docs say "Allows specification of the declaring module." ; I would add --module specifies which existing module should be modified to import the module you are about to create

                            – The Red Pea
                            May 27 '18 at 14:27








                          • 1





                            @TheRedPea I believe you meant to say " --module specifies which existing module should be modified to import the component you are ..."

                            – cobolstinks
                            Jul 3 '18 at 14:14











                          • Yep you're right! Existing module modified with reference to new component

                            – The Red Pea
                            Jul 3 '18 at 17:04



















                          • Yay for the --module argument; the docs say "Allows specification of the declaring module." ; I would add --module specifies which existing module should be modified to import the module you are about to create

                            – The Red Pea
                            May 27 '18 at 14:27








                          • 1





                            @TheRedPea I believe you meant to say " --module specifies which existing module should be modified to import the component you are ..."

                            – cobolstinks
                            Jul 3 '18 at 14:14











                          • Yep you're right! Existing module modified with reference to new component

                            – The Red Pea
                            Jul 3 '18 at 17:04

















                          Yay for the --module argument; the docs say "Allows specification of the declaring module." ; I would add --module specifies which existing module should be modified to import the module you are about to create

                          – The Red Pea
                          May 27 '18 at 14:27







                          Yay for the --module argument; the docs say "Allows specification of the declaring module." ; I would add --module specifies which existing module should be modified to import the module you are about to create

                          – The Red Pea
                          May 27 '18 at 14:27






                          1




                          1





                          @TheRedPea I believe you meant to say " --module specifies which existing module should be modified to import the component you are ..."

                          – cobolstinks
                          Jul 3 '18 at 14:14





                          @TheRedPea I believe you meant to say " --module specifies which existing module should be modified to import the component you are ..."

                          – cobolstinks
                          Jul 3 '18 at 14:14













                          Yep you're right! Existing module modified with reference to new component

                          – The Red Pea
                          Jul 3 '18 at 17:04





                          Yep you're right! Existing module modified with reference to new component

                          – The Red Pea
                          Jul 3 '18 at 17:04











                          9














                          You can try below command, which describes the,



                          ng -> Angular 
                          g -> Generate
                          c -> Component
                          -m -> Module


                          Then your command will be like:



                          ng g c user/userComponent -m user.module





                          share|improve this answer






























                            9














                            You can try below command, which describes the,



                            ng -> Angular 
                            g -> Generate
                            c -> Component
                            -m -> Module


                            Then your command will be like:



                            ng g c user/userComponent -m user.module





                            share|improve this answer




























                              9












                              9








                              9







                              You can try below command, which describes the,



                              ng -> Angular 
                              g -> Generate
                              c -> Component
                              -m -> Module


                              Then your command will be like:



                              ng g c user/userComponent -m user.module





                              share|improve this answer















                              You can try below command, which describes the,



                              ng -> Angular 
                              g -> Generate
                              c -> Component
                              -m -> Module


                              Then your command will be like:



                              ng g c user/userComponent -m user.module






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Nov 20 '18 at 12:17









                              keepAlive

                              3,16541224




                              3,16541224










                              answered Jul 1 '18 at 22:12









                              user2662006user2662006

                              1,5351412




                              1,5351412























                                  6














                                  this is what worked for me :



                                  1 -->  ng g module new-module

                                  2 --> ng g c new-module/component-test --module=new-module/new-module.module.ts


                                  If you want to generate a component without its directory use --flat flag.






                                  share|improve this answer
























                                  • don't need to write .ts

                                    – Lapenkov Vladimir
                                    Jun 30 '18 at 7:10











                                  • --module=path-to-module worked form me thanks @Mohamed Makkaoui

                                    – Ian Poston Framer
                                    Sep 18 '18 at 6:24











                                  • you're welcome @IanPostonFramer

                                    – Mohamed Makkaoui
                                    Sep 18 '18 at 11:13
















                                  6














                                  this is what worked for me :



                                  1 -->  ng g module new-module

                                  2 --> ng g c new-module/component-test --module=new-module/new-module.module.ts


                                  If you want to generate a component without its directory use --flat flag.






                                  share|improve this answer
























                                  • don't need to write .ts

                                    – Lapenkov Vladimir
                                    Jun 30 '18 at 7:10











                                  • --module=path-to-module worked form me thanks @Mohamed Makkaoui

                                    – Ian Poston Framer
                                    Sep 18 '18 at 6:24











                                  • you're welcome @IanPostonFramer

                                    – Mohamed Makkaoui
                                    Sep 18 '18 at 11:13














                                  6












                                  6








                                  6







                                  this is what worked for me :



                                  1 -->  ng g module new-module

                                  2 --> ng g c new-module/component-test --module=new-module/new-module.module.ts


                                  If you want to generate a component without its directory use --flat flag.






                                  share|improve this answer













                                  this is what worked for me :



                                  1 -->  ng g module new-module

                                  2 --> ng g c new-module/component-test --module=new-module/new-module.module.ts


                                  If you want to generate a component without its directory use --flat flag.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Nov 23 '17 at 16:45









                                  Mohamed MakkaouiMohamed Makkaoui

                                  7828




                                  7828













                                  • don't need to write .ts

                                    – Lapenkov Vladimir
                                    Jun 30 '18 at 7:10











                                  • --module=path-to-module worked form me thanks @Mohamed Makkaoui

                                    – Ian Poston Framer
                                    Sep 18 '18 at 6:24











                                  • you're welcome @IanPostonFramer

                                    – Mohamed Makkaoui
                                    Sep 18 '18 at 11:13



















                                  • don't need to write .ts

                                    – Lapenkov Vladimir
                                    Jun 30 '18 at 7:10











                                  • --module=path-to-module worked form me thanks @Mohamed Makkaoui

                                    – Ian Poston Framer
                                    Sep 18 '18 at 6:24











                                  • you're welcome @IanPostonFramer

                                    – Mohamed Makkaoui
                                    Sep 18 '18 at 11:13

















                                  don't need to write .ts

                                  – Lapenkov Vladimir
                                  Jun 30 '18 at 7:10





                                  don't need to write .ts

                                  – Lapenkov Vladimir
                                  Jun 30 '18 at 7:10













                                  --module=path-to-module worked form me thanks @Mohamed Makkaoui

                                  – Ian Poston Framer
                                  Sep 18 '18 at 6:24





                                  --module=path-to-module worked form me thanks @Mohamed Makkaoui

                                  – Ian Poston Framer
                                  Sep 18 '18 at 6:24













                                  you're welcome @IanPostonFramer

                                  – Mohamed Makkaoui
                                  Sep 18 '18 at 11:13





                                  you're welcome @IanPostonFramer

                                  – Mohamed Makkaoui
                                  Sep 18 '18 at 11:13











                                  4














                                  For Angular v4 and Above, simply use:



                                  ng g c componentName -m ModuleName





                                  share|improve this answer





















                                  • 1





                                    Throws an error Specified module does not exist whereas module existed

                                    – Pardeep Jain
                                    May 28 '18 at 10:20






                                  • 1





                                    You don't specify the name of the module, you specify the module's filename.

                                    – Roger
                                    Jun 6 '18 at 8:46
















                                  4














                                  For Angular v4 and Above, simply use:



                                  ng g c componentName -m ModuleName





                                  share|improve this answer





















                                  • 1





                                    Throws an error Specified module does not exist whereas module existed

                                    – Pardeep Jain
                                    May 28 '18 at 10:20






                                  • 1





                                    You don't specify the name of the module, you specify the module's filename.

                                    – Roger
                                    Jun 6 '18 at 8:46














                                  4












                                  4








                                  4







                                  For Angular v4 and Above, simply use:



                                  ng g c componentName -m ModuleName





                                  share|improve this answer















                                  For Angular v4 and Above, simply use:



                                  ng g c componentName -m ModuleName






                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Apr 4 '18 at 2:41









                                  Stephen Rauch

                                  29.7k153657




                                  29.7k153657










                                  answered Apr 4 '18 at 2:23









                                  ShemzzShemzz

                                  414




                                  414








                                  • 1





                                    Throws an error Specified module does not exist whereas module existed

                                    – Pardeep Jain
                                    May 28 '18 at 10:20






                                  • 1





                                    You don't specify the name of the module, you specify the module's filename.

                                    – Roger
                                    Jun 6 '18 at 8:46














                                  • 1





                                    Throws an error Specified module does not exist whereas module existed

                                    – Pardeep Jain
                                    May 28 '18 at 10:20






                                  • 1





                                    You don't specify the name of the module, you specify the module's filename.

                                    – Roger
                                    Jun 6 '18 at 8:46








                                  1




                                  1





                                  Throws an error Specified module does not exist whereas module existed

                                  – Pardeep Jain
                                  May 28 '18 at 10:20





                                  Throws an error Specified module does not exist whereas module existed

                                  – Pardeep Jain
                                  May 28 '18 at 10:20




                                  1




                                  1





                                  You don't specify the name of the module, you specify the module's filename.

                                  – Roger
                                  Jun 6 '18 at 8:46





                                  You don't specify the name of the module, you specify the module's filename.

                                  – Roger
                                  Jun 6 '18 at 8:46











                                  1














                                  Use this simple command:



                                  ng g c users/userlist


                                  users: Your module name.



                                  userlist: Your component name.






                                  share|improve this answer






























                                    1














                                    Use this simple command:



                                    ng g c users/userlist


                                    users: Your module name.



                                    userlist: Your component name.






                                    share|improve this answer




























                                      1












                                      1








                                      1







                                      Use this simple command:



                                      ng g c users/userlist


                                      users: Your module name.



                                      userlist: Your component name.






                                      share|improve this answer















                                      Use this simple command:



                                      ng g c users/userlist


                                      users: Your module name.



                                      userlist: Your component name.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Jan 29 '18 at 17:32

























                                      answered Jan 29 '18 at 13:24









                                      Hasan FathiHasan Fathi

                                      2,19012026




                                      2,19012026























                                          1














                                          According to Angular docs the way to create a component for specific module is,



                                          ng g component <directory name>/<component name>


                                          "directory name" = where the CLI generated the feature module



                                          Example :-



                                          ng generate component customer-dashboard/CustomerDashboard


                                          This generates a folder for the new component within the customer-dashboard folder and updates the feature module with the CustomerDashboardComponent






                                          share|improve this answer




























                                            1














                                            According to Angular docs the way to create a component for specific module is,



                                            ng g component <directory name>/<component name>


                                            "directory name" = where the CLI generated the feature module



                                            Example :-



                                            ng generate component customer-dashboard/CustomerDashboard


                                            This generates a folder for the new component within the customer-dashboard folder and updates the feature module with the CustomerDashboardComponent






                                            share|improve this answer


























                                              1












                                              1








                                              1







                                              According to Angular docs the way to create a component for specific module is,



                                              ng g component <directory name>/<component name>


                                              "directory name" = where the CLI generated the feature module



                                              Example :-



                                              ng generate component customer-dashboard/CustomerDashboard


                                              This generates a folder for the new component within the customer-dashboard folder and updates the feature module with the CustomerDashboardComponent






                                              share|improve this answer













                                              According to Angular docs the way to create a component for specific module is,



                                              ng g component <directory name>/<component name>


                                              "directory name" = where the CLI generated the feature module



                                              Example :-



                                              ng generate component customer-dashboard/CustomerDashboard


                                              This generates a folder for the new component within the customer-dashboard folder and updates the feature module with the CustomerDashboardComponent







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Aug 30 '18 at 11:12









                                              Sksaif UddinSksaif Uddin

                                              17728




                                              17728























                                                  0














                                                  Add a component to the Angular 4 app using Angular CLI



                                                  To add a new Angular 4 component to the app, use command ng g component componentName. After execution of this command, Angular CLI adds a folder component-name under srcapp. Also, the references of the same is added to srcappapp.module.ts file automatically.



                                                  A component shall have a @Component decorator function followed by a class which needs to be exported. The @Component decorator function accepts meta data.



                                                  Add a component to specific folder of the Angular 4 app using Angular CLI



                                                  To add a new component to a specific folder use the command ng g component folderName/componentName






                                                  share|improve this answer




























                                                    0














                                                    Add a component to the Angular 4 app using Angular CLI



                                                    To add a new Angular 4 component to the app, use command ng g component componentName. After execution of this command, Angular CLI adds a folder component-name under srcapp. Also, the references of the same is added to srcappapp.module.ts file automatically.



                                                    A component shall have a @Component decorator function followed by a class which needs to be exported. The @Component decorator function accepts meta data.



                                                    Add a component to specific folder of the Angular 4 app using Angular CLI



                                                    To add a new component to a specific folder use the command ng g component folderName/componentName






                                                    share|improve this answer


























                                                      0












                                                      0








                                                      0







                                                      Add a component to the Angular 4 app using Angular CLI



                                                      To add a new Angular 4 component to the app, use command ng g component componentName. After execution of this command, Angular CLI adds a folder component-name under srcapp. Also, the references of the same is added to srcappapp.module.ts file automatically.



                                                      A component shall have a @Component decorator function followed by a class which needs to be exported. The @Component decorator function accepts meta data.



                                                      Add a component to specific folder of the Angular 4 app using Angular CLI



                                                      To add a new component to a specific folder use the command ng g component folderName/componentName






                                                      share|improve this answer













                                                      Add a component to the Angular 4 app using Angular CLI



                                                      To add a new Angular 4 component to the app, use command ng g component componentName. After execution of this command, Angular CLI adds a folder component-name under srcapp. Also, the references of the same is added to srcappapp.module.ts file automatically.



                                                      A component shall have a @Component decorator function followed by a class which needs to be exported. The @Component decorator function accepts meta data.



                                                      Add a component to specific folder of the Angular 4 app using Angular CLI



                                                      To add a new component to a specific folder use the command ng g component folderName/componentName







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered Aug 14 '17 at 19:26









                                                      studentstudent

                                                      11k969130




                                                      11k969130























                                                          0














                                                          I am having the similar issues with multiple modules in application. A component can be created to any module so before creating a component we have to specify the name of the particular module.



                                                          'ng generate component newCompName --module= specify name of module'





                                                          share|improve this answer




























                                                            0














                                                            I am having the similar issues with multiple modules in application. A component can be created to any module so before creating a component we have to specify the name of the particular module.



                                                            'ng generate component newCompName --module= specify name of module'





                                                            share|improve this answer


























                                                              0












                                                              0








                                                              0







                                                              I am having the similar issues with multiple modules in application. A component can be created to any module so before creating a component we have to specify the name of the particular module.



                                                              'ng generate component newCompName --module= specify name of module'





                                                              share|improve this answer













                                                              I am having the similar issues with multiple modules in application. A component can be created to any module so before creating a component we have to specify the name of the particular module.



                                                              'ng generate component newCompName --module= specify name of module'






                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Sep 9 '17 at 4:32









                                                              vivekvivek

                                                              546




                                                              546























                                                                  0














                                                                  If you have multiple apps declared in .angular-cli.json ( e.g. in case working on feature module)



                                                                  "apps": [{
                                                                  "name": "app-name",
                                                                  "root": "lib",
                                                                  "appRoot": ""
                                                                  }, {...} ]


                                                                  You can :



                                                                  ng g c my-comp -a app-name


                                                                  -a stands for --app (name)






                                                                  share|improve this answer




























                                                                    0














                                                                    If you have multiple apps declared in .angular-cli.json ( e.g. in case working on feature module)



                                                                    "apps": [{
                                                                    "name": "app-name",
                                                                    "root": "lib",
                                                                    "appRoot": ""
                                                                    }, {...} ]


                                                                    You can :



                                                                    ng g c my-comp -a app-name


                                                                    -a stands for --app (name)






                                                                    share|improve this answer


























                                                                      0












                                                                      0








                                                                      0







                                                                      If you have multiple apps declared in .angular-cli.json ( e.g. in case working on feature module)



                                                                      "apps": [{
                                                                      "name": "app-name",
                                                                      "root": "lib",
                                                                      "appRoot": ""
                                                                      }, {...} ]


                                                                      You can :



                                                                      ng g c my-comp -a app-name


                                                                      -a stands for --app (name)






                                                                      share|improve this answer













                                                                      If you have multiple apps declared in .angular-cli.json ( e.g. in case working on feature module)



                                                                      "apps": [{
                                                                      "name": "app-name",
                                                                      "root": "lib",
                                                                      "appRoot": ""
                                                                      }, {...} ]


                                                                      You can :



                                                                      ng g c my-comp -a app-name


                                                                      -a stands for --app (name)







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered Apr 24 '18 at 11:20









                                                                      SamSam

                                                                      1




                                                                      1























                                                                          0














                                                                          First run ng g module newModule
                                                                          . Then run ng g component newModule/newModule --flat






                                                                          share|improve this answer




























                                                                            0














                                                                            First run ng g module newModule
                                                                            . Then run ng g component newModule/newModule --flat






                                                                            share|improve this answer


























                                                                              0












                                                                              0








                                                                              0







                                                                              First run ng g module newModule
                                                                              . Then run ng g component newModule/newModule --flat






                                                                              share|improve this answer













                                                                              First run ng g module newModule
                                                                              . Then run ng g component newModule/newModule --flat







                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered Dec 26 '18 at 12:58









                                                                              Tuan van DuongTuan van Duong

                                                                              2828




                                                                              2828























                                                                                  0














                                                                                  I am currently working on angular 5 projects and I use this particular command for generating components inside a module.



                                                                                  ng g c <module-name>/<new-component-name>


                                                                                  This command will generate component local to the module if you use normal command eg



                                                                                  ng g c <component-name>


                                                                                  it will generate component inside the app module a.k.a root module.



                                                                                  Note: code enclosed in <> represent user specific names.






                                                                                  share|improve this answer




























                                                                                    0














                                                                                    I am currently working on angular 5 projects and I use this particular command for generating components inside a module.



                                                                                    ng g c <module-name>/<new-component-name>


                                                                                    This command will generate component local to the module if you use normal command eg



                                                                                    ng g c <component-name>


                                                                                    it will generate component inside the app module a.k.a root module.



                                                                                    Note: code enclosed in <> represent user specific names.






                                                                                    share|improve this answer


























                                                                                      0












                                                                                      0








                                                                                      0







                                                                                      I am currently working on angular 5 projects and I use this particular command for generating components inside a module.



                                                                                      ng g c <module-name>/<new-component-name>


                                                                                      This command will generate component local to the module if you use normal command eg



                                                                                      ng g c <component-name>


                                                                                      it will generate component inside the app module a.k.a root module.



                                                                                      Note: code enclosed in <> represent user specific names.






                                                                                      share|improve this answer













                                                                                      I am currently working on angular 5 projects and I use this particular command for generating components inside a module.



                                                                                      ng g c <module-name>/<new-component-name>


                                                                                      This command will generate component local to the module if you use normal command eg



                                                                                      ng g c <component-name>


                                                                                      it will generate component inside the app module a.k.a root module.



                                                                                      Note: code enclosed in <> represent user specific names.







                                                                                      share|improve this answer












                                                                                      share|improve this answer



                                                                                      share|improve this answer










                                                                                      answered Jan 29 at 4:48









                                                                                      Shashank RawatShashank Rawat

                                                                                      4117




                                                                                      4117






























                                                                                          draft saved

                                                                                          draft discarded




















































                                                                                          Thanks for contributing an answer to Stack Overflow!


                                                                                          • Please be sure to answer the question. Provide details and share your research!

                                                                                          But avoid



                                                                                          • Asking for help, clarification, or responding to other answers.

                                                                                          • Making statements based on opinion; back them up with references or personal experience.


                                                                                          To learn more, see our tips on writing great answers.




                                                                                          draft saved


                                                                                          draft discarded














                                                                                          StackExchange.ready(
                                                                                          function () {
                                                                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40649799%2fcreate-component-to-specific-module-with-angular-cli%23new-answer', 'question_page');
                                                                                          }
                                                                                          );

                                                                                          Post as a guest















                                                                                          Required, but never shown





















































                                                                                          Required, but never shown














                                                                                          Required, but never shown












                                                                                          Required, but never shown







                                                                                          Required, but never shown

































                                                                                          Required, but never shown














                                                                                          Required, but never shown












                                                                                          Required, but never shown







                                                                                          Required, but never shown







                                                                                          Popular posts from this blog

                                                                                          How to pass form data using jquery Ajax to insert data in database?

                                                                                          National Museum of Racing and Hall of Fame

                                                                                          Guess what letter conforming each word