Q1. What are the most commonly used Angular CLI commands?
Common commands: ng new (create new project), ng serve (run dev server), ng generate (generate components, services, etc.), ng build (build the app), ng test (run unit tests), ng e2e (run end-to-end tests), ng lint (lint code), ng update (update dependencies).
Each command has options for customization.
Each command has options for customization.
Q2. How do you generate a component using the CLI?
Use the generate command:
The CLI creates all necessary files and updates the module.
ng generate component component-name
Or shorthand:ng g c component-name
You can specify options like --skip-tests, --flat, or --module to declare in a specific module.The CLI creates all necessary files and updates the module.
Q3. What does the ng serve command do?
ng serve builds the application and starts a development server, usually on http://localhost:4200.
It watches for file changes, rebuilds, and live-reloads the browser.
Options include --port, --host, --open, and --configuration for using different environment configurations.
It''s the primary command for development.
It watches for file changes, rebuilds, and live-reloads the browser.
Options include --port, --host, --open, and --configuration for using different environment configurations.
It''s the primary command for development.
Q4. What is the difference between ng build and ng serve?
ng build compiles the application into an output directory (dist/ by default) for deployment.
It does not start a server.
ng serve compiles and serves the application from memory with live reload for development.
For production, you use ng build --prod which optimizes the build with minification, tree-shaking, and Ahead-of-Time (AOT) compilation.
It does not start a server.
ng serve compiles and serves the application from memory with live reload for development.
For production, you use ng build --prod which optimizes the build with minification, tree-shaking, and Ahead-of-Time (AOT) compilation.
Q5. How do you generate a service using the CLI?
Use:
This creates a service file and its test spec.
Unlike components, services are not automatically registered; you need to provide them in a module or component using the @Injectable decorator.
ng generate service service-name
Or: ng g s service-name.This creates a service file and its test spec.
Unlike components, services are not automatically registered; you need to provide them in a module or component using the @Injectable decorator.
