How to create component in using angular CLI

angular set up

Prerequisites

To install Angular CLI, Run the following command.



Create Component and Service

We can use either ng generate or ng g only to generate component/service. By using ng generate we can create component, Directive, Service and Pipes.

Examples

  •  Component : To create component run the below command.
    After successful execution, you will find your component in your project. In your project, you will be able to see four files .html, .css, .spec.ts and .ts 

    Syntax:

  • Service : Run below command to create service.

    Syntax:

    @Injectable() services

    Notice that the new service imports the Angular Injectable symbol and annotates the class with the @Injectable() decorator.

    The @Injectable() decorator tells Angular that this service might itself have injected dependencies. It doesn’t have dependencies now but it will soon. Whether it does or it doesn’t, it’s good practice to keep the decorator.

Please follow and like us:

You May Also Like

About the Author: Sujeet Kumar

Sujeet is Web and Android Devloper with a soft spot for functional programming. I like to play cricket, regular workout.

Leave a Reply

Your email address will not be published. Required fields are marked *