Angular CLI Commands

$ node –v
(to check the version of node)

$ npm install –g @angular/cli
(to install the Angular CLI globally on our machine)

$ ng –v
(to verify the version of Angular CLI)

$ ng new FirstApp
(to generate a new app of name FirstApp)

$ ng new FirstApp –-dry-run
(this command will only report the files and not write them)

$ ng new FirstApp –-skip-install
(this command will generate a new app without running the npm install)

$ ng new –-help
$ ng new -h
(will list out all the flags associated with the ng new command)

$ ng new FirstApp –-style scss
(will be using sass instead of css in the generated app)

$ ng new FirstApp –-prefix YourName
(will set the default selector as YourName)

$ ng new FirstApp –-skip-test
(will not generate the spec files while creating the app)

$ ng new FirstApp –-routing
(will generate a new app with a default routing module)

$ ng new FirstApp –-routing –-style scss –-prefix YourName
(example of the above flags in a command combined)

$ ng lint
(will do the linting of the TypeScript code)

$ ng lint –-help
(will list out all the options available with the lint command)

$ ng lint –-format stylish
(will lint and format the output in a coloured manner)

$ ng lint –-fix
(will lint and fix all the problems if any)

$ ng generate component User
$ ng g c User
(g --> alias for generate, c --> alias for component)
(will create user.component.ts)

$ ng g c star –-flat
(Will not create a /star folder)

$ ng g c star --inline-template --inline-style 
$ ng g c star –it –is
(Will not create template/html and css file, it will be inline in ts file)

$ng g c star --spec false
(Will not create a spec file)

$ ng g c star --prefix pj
(Prefix the component with pj-)


$ ng generate service user-data
$ ng g s user-data
(will create user-data.service.ts)

$ ng generate class user-model
$ ng g c user-model
(will create user-model.ts)

$ ng g module admin
$ ng g m admin 
(It will create admin.module.ts)

$ ng g m sales --routing
(It will create sales.module.ts and sales-routing.module.ts)


Leave a Comment