Getting error when tries to generate new angular components using command
ng g component login-form
Error locating module for declaration. No module files found.
I think angular CLI its throwing error since out of the box angular template in ASP.NET Core is has different file names, Please suggest alternative way to generate angular components in ASP.NET Core projects.
Just create a new file, and start typing.
The CLI's
g
(generate
) methods are simple scaffolders for components, which generate some files for you in a folder which you specify, and edit some other files. This is not a requirement for a project using CLI: you can create files yourself.For example, generating a component will
{{component-name}}.component.ts
with a class skeleton which has pre-filled metadata inside the@Component
decorator, a constructor and implementation of theOnInit
lifecycle hook,{{component-name}}.component.css
, or a different extension based on your settings in the.angular-cli.json
file,{{component-name}}.component.html
file which just states that your component is working,{{component-name}}.component.spec.ts
which tests for creation of a component, and -- add the component in thedeclarations
array of the corresponding Angular module.All of this is something you can do yourself, if you want to. For example, I do not use the CLI's
g
command when I'm creating very simple component, because I do not use separate files for the templates and the styles.By the way, the fact that you're using ASP as your back-end should not interfere with how you manage your front-end application. Angular is a framework for building single-page applications which means that your backend be an API separate from the Angular application which will only serve as a client.
As for why you're getting the error -- are you trying to do an
ng g
command in a project which was notng new
d?The other possible source of the error is that you're trying to create it in the folder which is not an Angular module. To get there, just navigate through your structure.