FrontEndTech
  • Introduction
  • ReactJS
    • Ecosystem
    • Refactor Using Functional Decomposition and Reducer Composition
  • AngularJS
    • installation
    • File structure
    • CLI
      • ng g
    • Fundamentals
      • Component
        • Lifecycle
        • Template
      • Decorations
      • Service
      • Pipe
      • Directives
        • NgClass
        • NgStyle
        • NgModel
        • Customized Attribute Directives
        • NgIf
        • NgFor
        • NgSwitch
        • NgForm
        • Customized Structural Directives
      • Module
        • Routing
    • Bindings
      • Property Binding
      • Event Binding
      • Data Binding
      • Attribute Binding
      • Class Binding
      • Style Binding
    • Forms
      • Reactive Form
      • Reactive vs Template
    • build
Powered by GitBook
On this page
  • The Angular CLI
  • ng generate
  • Component
  • Service
  • Module
  • Directives

Was this helpful?

  1. AngularJS

CLI

PreviousFile structureNextng g

Last updated 5 years ago

Was this helpful?

The Angular CLI

[R]

a command line interface tool that can create a project, add files, and perform a variety of ongoing development tasks such as testing, bundling, and deployment.

Generate a new project and skeleton application

ng new my-app --routing
cd my-app
ng serve --open

The ng serve command launches the server, watches your files, and rebuilds the app as you make changes to those files.

the --open (or just -o) option will automatically open your browser on .

ng generate

Component

ng generate component <component_name>
ng g c <component_name>

ng generate component module_name/heroes --spec=false (no spec file)
ng generate component heroes -it  (inline template)

Service

There are several ways to provide the HeroService: in the HeroesComponent, in the AppComponent, in the AppModule. Each option has pros and cons.

ng generate service hero
ng g s core/<service_name> --module=core

ng generate service hero

ng generate service core/hero --module=core
ng generate service hero --spec=false --module=app

Module

ng generate module <module_name>
ng g m <module_name>

ng g m share --routing --module=app
ng g m core --module=app
ng generate module app-routing --flat --module=app --routing

--flat puts the file in src/app instead of its own folder. --module=app tells the CLI to register it in the imports array of the AppModule.

Directives

ng generate directives <directive_name>
ng g d <directive_name>

ng g d Demo --spec=false
https://github.com/angular/angular-cli/wiki
http://localhost:4200/