Working on ASP.NET core project (Angular) & Visual Studio as my IDE.
Is there an easy way to generate Angular component files and register the new component in the app module in Visual Studio?
Working on ASP.NET core project (Angular) & Visual Studio as my IDE.
Is there an easy way to generate Angular component files and register the new component in the app module in Visual Studio?
On
I found the answer from the following article: Exploring Angular Fundamental With Visual Studio 2017 (I did this in VS 2019)
Just open the integrated terminal in VS Code and use the Angular CLI commands
ng generateor its aliasng g. Here's the list of some options that you can use with the ng g command:ng g c- generate a new componentng g s- generate a new serviceng g d- generate a new directiveng g m- generate a new moduleng g p- generate a new pipeEach of these commands requires an argument(s), e.g. the name of the component to generate. For the complete list of available options and arguments run the command
ng helpgenerate or refer to the Angular CLI documentation. Here are some of the examples of using theng gcommand:ng g c productwill generate four files (.ts, .html, .css, .spec.ts) for a new product component in the directory src/app/product and will add the ProductComponent class to the declaration property of@NgModuleng g c product -is -it -spec=falsewill generate a single file product.component.ts with inlined styles and a template in the directory src/app/product and will add ProductComponent to the declarations property of@NgModuleng g s productwill generate file product.service.ts containing a class decorated with@Injectable()and the file product.service.spec.ts in the directory src/appng g s product -m app.modulewill generate the same files as the above command and will also add ProductService to theprovidersproperty of@NgModule