Angular important topics
1. What is Angular?
Purpose and Functionality:
- The Angular CLI allows developers to interact with Angular projects directly from the command line.
- It simplifies tasks such as project initialization, scaffolding, and building.
- Developers can create new Angular projects, add components, services, and other features, and manage project configurations.
Installation:
- To install the Angular CLI, use the following command with npm (Node Package Manager):
npm install -g @angular/cli
- The
-g
flag ensures that the CLI is installed globally on your system.
- To install the Angular CLI, use the following command with npm (Node Package Manager):
Basic Workflow:
- Once installed, you can invoke the Angular CLI using the
ng
executable. - Here are some common commands:
- To create a new Angular project:
ng new my-first-project
- To serve the project locally for development:
cd my-first-project ng serve
- The local development server automatically rebuilds the application and reloads the page when you change source files.
- To create a new Angular project:
- Once installed, you can invoke the Angular CLI using the
Workspace and Project Structure:
- The Angular CLI creates an Angular workspace folder, which can contain multiple applications and libraries.
- The initial application (created by
ng new
) resides at the top level of the workspace. - Additional applications or libraries are generated in the
projects/
subfolder. - Each application has a
src/
folder containing logic, data, and assets. - You can edit generated files directly or use CLI commands to add new components, services, and more.
Configuration:
- The main configuration file for the workspace is
angular.json
. - It allows you to set defaults for CLI options and specify configurations for different build targets.
Developed and maintained by Google: Angular is backed by Google, which means it has a strong foundation and ongoing support.
Large community and ecosystem:
Angular has a large and active community of developers, which makes it easier to find help, tutorials, and libraries.
Two-way data binding:
Angular provides two-way data binding, allowing changes in the model to automatically update the view and vice versa.
Use of TypeScript:
Angular is built with TypeScript, a statically typed superset of JavaScript. TypeScript adds features like static type checking, interfaces, and better tooling support.
Support for i18n (Internationalization):
Angular has built-in support for internationalization, making it easier to create multilingual applications.
Support for lazy loading:
Angular allows you to load modules lazily, improving performance by loading only the necessary parts of your application when needed.
Dependency injection:
Angular’s dependency injection system simplifies managing dependencies and promotes modular code.
Powerful router:
Angular’s router provides features like route guards, lazy loading, and nested routes, making it easy to create complex navigation structures.
ngOnInit: This hook is called after Angular has initialized all data-bound properties of a directive or component.
ngOnChanges: This hook is called when any data-bound property of a directive or component changes.
ngDoCheck: This hook is called during every change detection cycle, allowing you to implement your own custom change detection logic.
ngAfterContentInit: This hook is called after Angular projects external content into the component's view.
ngAfterContentChecked: This hook is called after Angular checks the content projected into the component's view.
ngAfterViewInit: This hook is called after Angular initializes the component's views and child views.
ngAfterViewChecked: This hook is called after Angular checks the component's views and child views.
ngOnDestroy: This hook is called just before Angular destroys the directive or component.