Angular

Angular

  • Mahalakshmi
    Teacher
    Mahalakshmi
  • Category
    Nellie Hodkiewicz
  • Review
    • (20 Reviws)
Courses
Course Summery

Angular Essentials

Requrements

Angular Lecture Started

Angular Introduction:

          Angular is a popular open-source web application framework maintained by Google and a community of developers. It's used for building single-page client applications in HTML and TypeScript. Here's a breakdown of some key concepts and features to give you an introduction:

 

Architecture: Angular follows the MVC (Model-View-Controller) architecture pattern, but it's often described in terms of components. Components are the basic building blocks of an Angular application. Each component consists of three parts:

 

  • Template: This is the HTML code that defines the UI of the component.
  • Class: This is the TypeScript code that defines the behavior of the component.
  • Metadata: This provides extra information about the component, such as its selector and dependencies.
  • Data Binding: Angular provides powerful data binding capabilities, allowing you to synchronize data between the component class and its template. There are different types of data binding, including:

 

Interpolation: Allows you to embed expressions in HTML templates.

  • Property Binding: Binds the value of a property in the component class to an attribute of an HTML element.
  • Event Binding: Listens for events raised by HTML elements and executes a method in the component class.
  • Two-way Binding: Combines property binding and event binding to provide a convenient way to bind data between a component class and its template.

Dependency Injection: Angular has a built-in dependency injection system that helps manage the dependencies of components and services. This promotes modularity, reusability, and testability of code.

 

Routing: Angular provides a powerful router module that allows you to build single-page applications with multiple views. You can define routes for different URLs and load the appropriate components when those URLs are navigated to.

 

Directives: Directives are markers on a DOM element that tell Angular to do something with that element, such as modify its behavior or appearance. Angular comes with built-in directives like ngFor and ngIf, and you can also create custom directives to extend the framework's functionality.

 

Services: Services are singleton objects that are instantiated only once during the lifetime of an application. They are used to encapsulate logic that is not specific to any component, such as data access, logging, or communication with a backend server.

 

Modules: Angular applications are modular and organized into NgModules. Each NgModule declares a set of components, directives, pipes, and services that are related to each other. This helps in organizing the application into cohesive blocks of functionality.

 

History of Angular:

AngularJS (2009-2016):

  • AngularJS, the first version of Angular, was developed by Google and released in 2009.
  • It introduced concepts like two-way data binding and dependency injection, making it popular among developers for building dynamic web applications.
  • AngularJS used JavaScript and HTML to build applications, and it gained widespread adoption in the developer community.

Angular 2+ (2016-present):

 

  • Angular 2, released in 2016, marked a major overhaul of the framework. It was a complete rewrite of AngularJS, built with TypeScript.
  • The architecture was redesigned to be more modular and scalable, with a focus on performance and mobile support.
  • Angular 2 introduced the concept of components as the main building blocks of applications, along with features like a hierarchical dependency injection system, improved data binding syntax, and a more powerful router.
  • Following Angular 2, subsequent versions have been released under the name Angular (without the "JS" suffix), with regular updates and improvements. These versions include Angular 4, 5, 6, 7, 8, 9, 10, 11, and 12, each bringing new features, performance enhancements, and bug fixes.
  • The Angular team adopted a semantic versioning scheme, where major versions are released every six months with backward-compatible changes and updates.

Angular Ivy (2019-present):

  • Angular Ivy is the latest rendering engine introduced in Angular 9 and further enhanced in subsequent versions.
  • It offers significant improvements in bundle size, compilation time, and runtime performance.
  • Ivy also enables features like lazy loading of components, improved debugging and build times, and better support for tree-shakable dependencies.

 

 

1. Download Nodejs in chrome.

 

----------------------------------------------------------------------------------------------------

 

2. node --version      --> To check the nodejs version

3. npm --version       --> To check the npm version

 

----------------------------------------------------------------------------------------------------

 

4. To Install the Angular Software:

          npm install -g @angular/cli

 

----------------------------------------------------------------------------------------------------

 

5. To Create a new Project

          ng new ProjectName

If the Project does not contains Module File --> ng new ProjectName --no-standalone

 

----------------------------------------------------------------------------------------------------

 

6. To open a Project in the VS code

          code ProjectName

 

----------------------------------------------------------------------------------------------------

 

7. To Create a Component

          ng g c ComponentName

 

g --> generate

c --> Component

 

----------------------------------------------------------------------------------------------------

8. To install a Bootstrap in Angular

          ng install bootstrap --save

----------------------------------------------------------------------------------------------------

9. To install jquery in Angular

          ng install jquery --save

----------------------------------------------------------------------------------------------------

 

10. To Run a Project

          ng serve

----------------------------------------------------------------------------------------------------

 

Data Binding:

          In Angular, data binding is a powerful feature that allows you to define communication between a component and its template. It synchronizes the data between the component and the view, making it easy to build dynamic and interactive web applications.

Interpolation{{}}:

          interpolation is a form of one-way data binding where you bind data from the component class to the template. You enclose the expression within double curly braces ({{...}}) in the template, and Angular replaces it with the evaluated value.

Example:

Property Binding:

Property binding allows you to set an element's property to the value of a template expression. You use square brackets ([]) to bind the property to the component's property.

 

Event Binding:

Two way Binding:

          Two-way data binding in Angular allows you to establish a bidirectional data flow between a property of a component and an input field in the template. This means changes to the property in the component class are reflected in the template, and changes made in the template are propagated back to the component class.

          In Angular, two-way data binding is typically achieved using the ngModel directive along with banana-in-a-box syntax [(ngModel)]. To use two-way data binding, you need to import the FormsModule or ReactiveFormsModule in your Angular module.

Directives:

          In Angular, directives play a crucial role in enhancing the behavior and appearance of elements within your application. Let’s delve into the different types of directives:

Component Directive:

          Components are the most common type of directive in Angular. They are used to create reusable UI components with their own templates, styles, and behavior. Components are essentially directives with a template.

 

 

Structural Directive:

          Structural directives change the structure of the DOM by adding, removing, or manipulating elements based on conditions. They are preceded by an asterisk (*) in the template syntax.

Example:

*ngFor:

          *ngFor is a structural directive in Angular used for rendering lists of items. It allows you to iterate over a collection of data and generate HTML elements for each item in the collection. The *ngFor directive is often used in conjunction with an array or an iterable object to dynamically create a set of elements based on the data.

Output:

 

*ngFor with an array of Object:

Output:

*ngIf:

          In Angular, the ngIf directive serves to dynamically remove or recreate sections of HTML elements based on an expression. When the expression evaluates to false, the corresponding element is removed from the DOM. Conversely, if the expression is true, the element is added to the DOM.

          In Angular, ngIf can be paired with ngElse to define an alternative content when the condition is false, and ngIf can also be combined with ngThen and ngIfElse for asynchronous operations to show loading states.

Output:

 

ng-else:

 

 

ng-then: