Welcome Guest! (App Version 5.16)

websitnero logo name

Creating a New Component

How to create a new component in Angular?

The best way to create a component in Angular is by making use of Angular-CLI. This tool helps a lot while developing angular projects. By entering the code as follows you will generate a component.

> ng generate component component/home

OR simply:

> ng g c component/home

Note that here we are generating a component named 'home' inside a folder named component, which is a good practise. We could have simply written name of the component without setting it inside folder named 'component' but then it would be more messy and folder would be created directly inside 'app' folder. This would look ugly as later when more items would be generated like various services, models, pipes, then all these items (in absense of separate folder for each of them) would seem mixed among themselves inside app folder. Keeping separate folders for components, services, models, pipes, etc. would keep things organized.

WebsiteNero is highly optimized for learning various website developing technlogies. We try our best to add maximum modules and examples to help learn the concepts clearly and vividly. We try to present all content and examples as simple as we can removing any complexity to hurdle easy understanding. We try best provide you with worthful content, but we cannot guarantee full correctness of all the content on this site. While using this website, you agree to have read and accepted all our terms of use and conditions, cookie, and privacy policy. Copyright, 2013-2018 by websitenero.com. All Rights Reserved.