To create a new component in Angular, you can use the Angular CLI (Command Line Interface) which provides a set of commands to generate different parts of an Angular application. Here are the steps to create a new component:
Open a terminal or command prompt and navigate to the project directory where you want to create the new component.
Run the following command to generate a new component:
ng generate component component-name
component-name with the name of your new component. This command will generate the necessary files and folders for the new component in the project directory.
Once the component is generated, you can use it in other parts of your application by adding its selector to the HTML template of another component.
For example, if your new component has a selector of
app-my-component, you can use it in the HTML template of another component like this:
This will insert the content of your new component into the HTML template of the other component.
That’s it! You have successfully created a new component in Angular. You can now open the generated files and start modifying them to add your own functionality to the component.