Wednesday, May 23, 2018

Angular - Creating a Component using Angular CLI

Install Angular CLI

If you don't have Angular CLI you will need to install it using npm

npm install -g @angular/cli


Usage


ng g c products/product-detail.component --flat

ng = Angular CLI
g = generate
c = component
--flat = no folder will be created

This will create 4 files:

  src\app\products\product-detail\product-detail.component.css
  src\app\products\product-detail\product-detail.component.html
  src\app\products\product-detail\product-detail.component.spec.ts
  src\app\products\product-detail\product-detail.component.ts

It will update the file which will register the component in the app.module.ts:
  src\app\app.module.ts

It will also wire the components together putting some useful code in
src\app\products\product-detail\product-detail.component.ts


2 comments:

Susan said...

Thanks for this great post, i find it very interesting and very well thought out and put together. I look forward to reading your work in the future. Discover the most popular people ranked on Celebrity birthdays.

Vijayalakshmi said...

Nice blog. I finally found great post here Very interesting to read this article and very pleased to find this site. Great work!
I have a informative blog on angularJS. Please click the below link to learn more about AngularJS.
AngularJS training