Search code examples
angularmodulecommand

module + routing + component in angular


I try to create module + routing + component in angular I added the following command ng g m general-parameter --routing --route general-parameter --module=pages.module but it get error "Specified module 'pages.module' does not exist. Looked in the following directories: /src/app/pages/general-parameter /src/app/pages/pages.module /src/app/pages src/app/pages /src/app /src " What is the problem?? Thank you

I added the following command ng g m general-parameter --routing --route general-parameter --module=pages.module but it get error "Specified module 'pages.module' does not exist. Looked in the following directories: /src/app/pages/general-parameter /src/app/pages/pages.module /src/app/pages src/app/pages /src/app /src "


Solution

  • Use the following commands:

    ng g m generalParameter --routing=true 
    
    • ng g m generalParameter will create your module
    • --routing=true will create it as a routing module

     

    ng g c generalParameter --skip-tests=true -m=generalParameter
    
    • ng g c generalParameter will create your component
    • --skip-tests=true will skip generating the test file
    • -m=generalParameter will place your component under the specified module and automatically generate declarations under the module

    You can also run them in a single command by combining them like this:

    ng g m generalParameter --routing=true && ng g c generalParameter --skip-tests=true -m=generalParameter
    

    Hope this helps.