SlideShare ist ein Scribd-Unternehmen logo
1 von 36
1
Angular 9
Components,
TypeScript,
Architecture,
Dependency Injection,
Routing
2
Introduction
toAngular
 JavaScript framework
 Bootstraps JavaScript with HTML pages
 Enhances UI experience of user
 It is a framework for building web and mobile client-side
apps with JavaScript or more precisely a super-language of
JavaScript called TypeScript built by Microsoft
 It implements core and optional functionality as a set of
TypeScript libraries that you import into your apps.
 The framework, written in pure JavaScript, was intended to
decouple an application’s logic from DOM manipulation
3
Why
Angular?
 Detailed documentation
 Angular boasts detailed documentation where
developers can find all necessary information
 Angular Material.
 This collection of Material Design elements optimized
for Angular lets developers easily integrate UI
components.
 Great ecosystem of third-party components
 The popularity of Angular has resulted in the appearance
of thousands of additional tools and components that
can be used in Angular apps.
 Component-based architecture.
 According to this architecture, an app is divided into
independent logical and functional components.
 These components can easily be replaced and decoupled
as well as reused in other parts of an app.
 Component independence makes it easy to test a web
app and ensure that every component works seamlessly.
4
Why
Angular?
 Ahead-of-time compiler.
 Angular’s AOT compiler converts TypeScript and HTML into
JavaScript during the build process.
 This code is compiled before the browser loads your web app so
that it’s rendered much faster.
 An AOT compiler is also much more secure than a just-in-time
(JIT) compiler.
 CLI
 Allows you to create a new Angular project, add features to it,
and run unit and end-to-end tests with a few simple commands.
 Angular Elements.
 Starting with Angular 6, developers can easily add custom
elements to any web app built with React, JQuery, Vue, or any
other environment
 Ivy Renderer
 Ivy Renderer translates an app’s components and templates into
JavaScript code that can be displayed by a browser.
 The main characteristic of this tool is its tree shaking technique.
 During rendering, Ivy removes unused code to make it clearer
and smaller. As a result, web apps load faster.
5
Angular9
Features and Fixes
6
Features and
Fixes
 Enables AOT compiler on by default
 This means that the AOT builds will be noticeably faster.
The change in the compiler and runtime, would no
longer require entryComponents and ng serve
 Default Ivy compiler
 Improves the bundle sizes.
 Allows for better debugging
 Faster Mobile Apps
 By reducing the size of JavaScript bundles, Ivy opens
a platform for developers to speed up the
application
 Adds improved TypeChecking & faster testing
 More reliable ng update
 ng update --create-commits, the tool commits the state
of our codebase after each migration, to debug the
changes made to the code.
 Selector-less directives in Ivy
 Improved internationalzation (i18n)
7
Features and
Fixes
 New options for 'providedIn'
 This angular 9 feature provides us with some additional
options while create an @Injectable service in Angular.
 platform - providedIn: 'platform' makes the service available
in a special singleton platform injector that is shared by all
applications on the page.
 any - Provides a unique instance in every module (including
lazy modules) that instills the token.
 TypeScript 3.7 Support
 Optional chaining
 Nullish Coalescing
 Assertion function
 Semicolon formatter option
 Uncalled function checks
 Component Hareness
 Angular 9 is making harnesses available to any component
author as part of the Component Dev Kit (CDK)
8
Angular9
Installation and Configurations
9
Installation and
Configurations
 Need to install Node.js to use npm
 Run the following command in command prompt to install Angular CLI and
create new project
 npm install -g @angular/cli
 ng new
 The Angular CLI makes it easy to create an application that already works,
right out of the box
 When you run ng new my-dream-app a new folder, named my-dream-app,
will be created in the current working directory.
 ng serve
 Build an app and serve it locally, the server automatically rebuilds the
app and reloads the page when you change any of the source files
10
Commands
 ng build
 Compiles an Angular app into an output directory named
dist at the given output path
 ng test
 Runs karma task runner for our tests
 ng generate
 Generates and/or modifies files based on a schematic
 ng e2e
 Builds and serves an Angular app, then runs end-to-end
tests using Protractor
 ng lint
 Runs linting tools on Angular app code in a given project
folder [ tslint.json ]
10
11
Key
Components
• The default root component
 File app-routing.module.ts contains url mapping of components
 File app.component.ts contains definition of root component
 File app.module.ts contains configuration of the component
 File app.component.html contains template component
 Index.html bootstraps root component.
12
Component
creation
 Creating a new component
 Generated new component will be updated
in app.module.ts
12
13
Angular9
TypeScript
14
Introduction
14
Improvements over ES6
Types Classes Annotations Imports exports
Language Utilities
(e.g. destructuring)
TypeChecking
Official collaboration between Microsoft and Google
TypeScript = JavaScript + Strong typing
TypeScript introduced fromAngular 2+.
15
JavaScript and
TypeScript
 JavaScript and TypeScript is superset of ES
 ES => EcmaScript
 ES is a standard JS,TS are implementation
 ES 6+ Modern JavaScripts.
 No types in JavaScript(loosely coupled)
 Example of number type in TypeScript
15
• this.id = "saw" // throws compilation error
16
Angular 9 - TypeScript built-in types
16
17
TypeScript -
Classes
17
In ES5, OO programming was accomplished by using prototype-based objects
TS classes may have properties methods and constructors
Inheritance built in core language
Uses extends keyword
To call a method of a class, we have to create an instance of this class, with the
new keyword
Constructor
• Named constructor(..)
• Doesn’t return any values
18
Angular 9 Architecture
Modules,Templates, MetaData,
DataBinding, Directives,Services
19
Architecture
Diagram
19
20
Architecture -
Modules
20
Angular apps are modular:
• An application defines a set of Angular Modules or NgModules
Every angular module is a class with an @NgModule decorator
Every Angular App has at least one module: the root module
NgModule takes a single metadata object describing the module, with the
following properties
• Declarations: view classes (components, directives and piped)
• Exports: subset of public declarations, usable in the templates of other modules
• Imports: external modules needed by the templates of this module
• Providers: creators of services that this module contributes to
• Bootstrap: main application view, called the root component, that hosts all other app views
21
Architecture
Templates
 A snippet of the HTML code of a component
 A component's view is defined with its template
 Uses Angular's template syntax, with custom elements
22
Architecture
MetaData
 Helps angular how to process data
 Uses decorators to attach information to a class:
 @Component
 Selector : source of the base address (module.id) for
module-relative URLs
 TemplateUrl : address of the component's HTML
template
 Providers : : array of dependency injection providers
for services that the component requires
 StyleUrls : CSS address for the template code
 Other metadata decorators: • @Injectable, @Input, @Output,..
22
23
DataBinding
 Mechanism for coordinating parts of a template
with parts of a component
 Four main forms
 Interpolation {{...}} :
 Displays the component's todo property
value within the <td> element
 Property Binding [….] :
 Passes the value of id to the child
comp
 <view-todo>
 Event Binding (click) :
 Calls the component's updateTodo()
method when the user clicks update
button
 Two-way data-binding [(ngModel)] :
 Combines property and event binding,
with ngModel
23
24
Directives
 Angular templates are dynamic
 When Angular renders them, it transforms the DOM
according to instructions given by directives
 A directive is a class with the @Directive decorator
 A component is a directive-with-a-template
 Two types of directives
 Structural directives
 Alter the layout by adding, removing and replacing
elements in the DOM
 <li *ngFor="let todo of todos"></li>
 <view-todo *ngIf="idNotNull"> <view-todo>
 Attribute directives
 Alter the appearance or behaviour of an existant
element
 Look like regular HTML attributes
 <input type='text' [(ngModel)] ="user.username">
24
25
Architecture -
Services
25
Service is a class with a narrow, well-defined purpose
• Logging service, data service..
Component classes should be lean,
• They shouldn't fetch data from the server,
• They just deal with user experience, mediate between the view and the logic,
• Everything non trivial should be delegated to services
ng generate service <service-name>
A service is associated to a component using dependency
injection
26
Angular9
Dependency Injection
27
Dependency
Injection -
Introduction
Important design pattern
Commonly called DI
A way to supply a new instance of a class with the fully-formed dependencies it
requires
In plain English, one object supplying the dependencies of another object.
Makes code more readable and maintainable.
Most dependencies are services
• DI is used to provide new components with the services they need
• It knows which services to instantiate by looking at the types of the component's constructor parameters
• constructor(private service : Service)
28
Injector
 When Angular creates a component, it asks an injector for the
services it requires
 Component asks an injector for the services it requires
 Maintains a container of service instances
 If a requested service instance is not in the container, the
injector makes one and adds it to the container before
returning the service to Angular
 When all requested services have been resolved and returned,
Angular can call the component's constructor with those
services as arguments
Serive A Serice B Service C
Component
Constructor(private service : Service B)
Inectors
29
 Provider: Creates or returns a service
 It is registered in a module or a component
 Add it to the root module for it to be available
everywhere
 Register it in the component to get a new instance of
the service with each new instance of the component
 @NgModule(
 { imports : [ ... ],
 providers:[ TodoDataService, LogService ]
 })
 @Injectable() marks a class as available to an injector for
instantiation
 @Injectable({
 providedIn: 'root',
 })
 Essential ingredient in every Angular service definition
Dependency
Injection Providers
& @Injectable
29
30
Angular 9
Routing
31
Routing -
Introduction
 Enables navigation from one view to the next as users
perform application tasks
 Interprets a browser URL as an instruction to navigate
to a clientgenerated view
 Can pass optional parameters to the supporting view
component to help it decide which specific content to
display
 Logs activity in the browser's history journal so the
back and forward buttons work
32
Routing Module
[ app-routing.module.ts ]
 For simple routing, defining the routes in the main
application module is fine
 It can become more difficult to manage if the
application grows and you use more Router features
 Refactor the routing configuration in its own file: the
Routing Module
 The Routing Module
 Separates routing concerns from other
application concerns
 Provides a module to replace or remove when
testing the application
 Provides a well-known location for routing
service providers •
 Does not declare components
33
Routing Module -
Example
 One singleton instance of
the Router service exists for
an application (app-
routing.module.ts)
 When the browser's URL
changes, that router looks
for the corresponding Route
to know which component
to display
 A router has no routes until
you configure it
 In order to render the
component chosen by
the router, a router-outlet is
inserted in the template
RouterLink used to navigate between pages
34
RouterGuard
Service
 Sometimes, routes need to be
protected: to prevent users from
accessing, areas that they're not
allowed to access, to ask for
permission etc.,
 Router Guards are applied to
routes to do that
 Four guard types:
 CanActivate: decides if a
route can be activated
 CanActivateChild: decides
if child routes of a route
can be activated
 CanDeactivate: decides if a
route can be deactivated
 CanLoad: decides if a
module can be loaded
lazily
35
Sites
Additional References
1. https://angular.io/docs - Angular Documentation
2. https://www.typescriptlang.org/docs/home.html -TypeScript Docs
3. https://cli.angular.io/ - Angular commands
Text books
• The Ng-book - A Complete Book on Angular (2020 Edition) https://www.newline.co/ng-book/2/
36
Thank you !

Weitere ähnliche Inhalte

Was ist angesagt?

Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Knoldus Inc.
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorialRohit Gupta
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - IntroductionWebStackAcademy
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular ComponentsSquash Apps Pvt Ltd
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of AngularKnoldus Inc.
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_contentNAVEENSAGGAM1
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of SignalsCoding Academy
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questionsGoa App
 
Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginnersImran Qasim
 
Vue.js Getting Started
Vue.js Getting StartedVue.js Getting Started
Vue.js Getting StartedMurat Doğan
 

Was ist angesagt? (20)

Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
Sharing Data Between Angular Components
Sharing Data Between Angular ComponentsSharing Data Between Angular Components
Sharing Data Between Angular Components
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
 
Angular
AngularAngular
Angular
 
AngularJS
AngularJSAngularJS
AngularJS
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
 
NestJS
NestJSNestJS
NestJS
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Angular Data Binding
Angular Data BindingAngular Data Binding
Angular Data Binding
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Angular Observables & RxJS Introduction
Angular Observables & RxJS IntroductionAngular Observables & RxJS Introduction
Angular Observables & RxJS Introduction
 
Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginners
 
Angular introduction students
Angular introduction studentsAngular introduction students
Angular introduction students
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Vue.js Getting Started
Vue.js Getting StartedVue.js Getting Started
Vue.js Getting Started
 

Ähnlich wie Angular 9

Introduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setupIntroduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setupAnsley Rodrigues
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptxtilejak773
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsWebStackAcademy
 
Angular4 getting started
Angular4 getting startedAngular4 getting started
Angular4 getting startedTejinderMakkar
 
Angular Course.pptx
Angular Course.pptxAngular Course.pptx
Angular Course.pptxImdad Ullah
 
Building a website with angular 2
Building a website with angular 2Building a website with angular 2
Building a website with angular 2Joseph Jorden
 
AngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesMohamad Al Asmar
 
Single Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSingle Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSparkhound Inc.
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type scriptRavi Mone
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentationdharisk
 
Building a website with angular
Building a website with angularBuilding a website with angular
Building a website with angularJoseph Jorden
 
Building Blocks of Angular 2 and ASP.NET Core
Building Blocks of Angular 2 and ASP.NET CoreBuilding Blocks of Angular 2 and ASP.NET Core
Building Blocks of Angular 2 and ASP.NET CoreLevi Fuller
 
Angular patterns
Angular patternsAngular patterns
Angular patternsPremkumar M
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to AngularjsGaurav Agrawal
 

Ähnlich wie Angular 9 (20)

Angular Basics.pptx
Angular Basics.pptxAngular Basics.pptx
Angular Basics.pptx
 
Introduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setupIntroduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setup
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
 
How Does Angular Work?
How Does Angular Work?How Does Angular Work?
How Does Angular Work?
 
Angular IO
Angular IOAngular IO
Angular IO
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
 
Angular 2.0
Angular  2.0Angular  2.0
Angular 2.0
 
Angular4 getting started
Angular4 getting startedAngular4 getting started
Angular4 getting started
 
Angular Course.pptx
Angular Course.pptxAngular Course.pptx
Angular Course.pptx
 
Building a website with angular 2
Building a website with angular 2Building a website with angular 2
Building a website with angular 2
 
AngularJS: Overview & Key Features
AngularJS: Overview & Key FeaturesAngularJS: Overview & Key Features
AngularJS: Overview & Key Features
 
Single Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSingle Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with Angular
 
Angular2 with type script
Angular2 with type scriptAngular2 with type script
Angular2 with type script
 
Angularjs2 presentation
Angularjs2 presentationAngularjs2 presentation
Angularjs2 presentation
 
Angular2
Angular2Angular2
Angular2
 
Building a website with angular
Building a website with angularBuilding a website with angular
Building a website with angular
 
Building Blocks of Angular 2 and ASP.NET Core
Building Blocks of Angular 2 and ASP.NET CoreBuilding Blocks of Angular 2 and ASP.NET Core
Building Blocks of Angular 2 and ASP.NET Core
 
Angular patterns
Angular patternsAngular patterns
Angular patterns
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
Angular js
Angular jsAngular js
Angular js
 

Kürzlich hochgeladen

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Kürzlich hochgeladen (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Angular 9

  • 2. 2 Introduction toAngular  JavaScript framework  Bootstraps JavaScript with HTML pages  Enhances UI experience of user  It is a framework for building web and mobile client-side apps with JavaScript or more precisely a super-language of JavaScript called TypeScript built by Microsoft  It implements core and optional functionality as a set of TypeScript libraries that you import into your apps.  The framework, written in pure JavaScript, was intended to decouple an application’s logic from DOM manipulation
  • 3. 3 Why Angular?  Detailed documentation  Angular boasts detailed documentation where developers can find all necessary information  Angular Material.  This collection of Material Design elements optimized for Angular lets developers easily integrate UI components.  Great ecosystem of third-party components  The popularity of Angular has resulted in the appearance of thousands of additional tools and components that can be used in Angular apps.  Component-based architecture.  According to this architecture, an app is divided into independent logical and functional components.  These components can easily be replaced and decoupled as well as reused in other parts of an app.  Component independence makes it easy to test a web app and ensure that every component works seamlessly.
  • 4. 4 Why Angular?  Ahead-of-time compiler.  Angular’s AOT compiler converts TypeScript and HTML into JavaScript during the build process.  This code is compiled before the browser loads your web app so that it’s rendered much faster.  An AOT compiler is also much more secure than a just-in-time (JIT) compiler.  CLI  Allows you to create a new Angular project, add features to it, and run unit and end-to-end tests with a few simple commands.  Angular Elements.  Starting with Angular 6, developers can easily add custom elements to any web app built with React, JQuery, Vue, or any other environment  Ivy Renderer  Ivy Renderer translates an app’s components and templates into JavaScript code that can be displayed by a browser.  The main characteristic of this tool is its tree shaking technique.  During rendering, Ivy removes unused code to make it clearer and smaller. As a result, web apps load faster.
  • 6. 6 Features and Fixes  Enables AOT compiler on by default  This means that the AOT builds will be noticeably faster. The change in the compiler and runtime, would no longer require entryComponents and ng serve  Default Ivy compiler  Improves the bundle sizes.  Allows for better debugging  Faster Mobile Apps  By reducing the size of JavaScript bundles, Ivy opens a platform for developers to speed up the application  Adds improved TypeChecking & faster testing  More reliable ng update  ng update --create-commits, the tool commits the state of our codebase after each migration, to debug the changes made to the code.  Selector-less directives in Ivy  Improved internationalzation (i18n)
  • 7. 7 Features and Fixes  New options for 'providedIn'  This angular 9 feature provides us with some additional options while create an @Injectable service in Angular.  platform - providedIn: 'platform' makes the service available in a special singleton platform injector that is shared by all applications on the page.  any - Provides a unique instance in every module (including lazy modules) that instills the token.  TypeScript 3.7 Support  Optional chaining  Nullish Coalescing  Assertion function  Semicolon formatter option  Uncalled function checks  Component Hareness  Angular 9 is making harnesses available to any component author as part of the Component Dev Kit (CDK)
  • 9. 9 Installation and Configurations  Need to install Node.js to use npm  Run the following command in command prompt to install Angular CLI and create new project  npm install -g @angular/cli  ng new  The Angular CLI makes it easy to create an application that already works, right out of the box  When you run ng new my-dream-app a new folder, named my-dream-app, will be created in the current working directory.  ng serve  Build an app and serve it locally, the server automatically rebuilds the app and reloads the page when you change any of the source files
  • 10. 10 Commands  ng build  Compiles an Angular app into an output directory named dist at the given output path  ng test  Runs karma task runner for our tests  ng generate  Generates and/or modifies files based on a schematic  ng e2e  Builds and serves an Angular app, then runs end-to-end tests using Protractor  ng lint  Runs linting tools on Angular app code in a given project folder [ tslint.json ] 10
  • 11. 11 Key Components • The default root component  File app-routing.module.ts contains url mapping of components  File app.component.ts contains definition of root component  File app.module.ts contains configuration of the component  File app.component.html contains template component  Index.html bootstraps root component.
  • 12. 12 Component creation  Creating a new component  Generated new component will be updated in app.module.ts 12
  • 14. 14 Introduction 14 Improvements over ES6 Types Classes Annotations Imports exports Language Utilities (e.g. destructuring) TypeChecking Official collaboration between Microsoft and Google TypeScript = JavaScript + Strong typing TypeScript introduced fromAngular 2+.
  • 15. 15 JavaScript and TypeScript  JavaScript and TypeScript is superset of ES  ES => EcmaScript  ES is a standard JS,TS are implementation  ES 6+ Modern JavaScripts.  No types in JavaScript(loosely coupled)  Example of number type in TypeScript 15 • this.id = "saw" // throws compilation error
  • 16. 16 Angular 9 - TypeScript built-in types 16
  • 17. 17 TypeScript - Classes 17 In ES5, OO programming was accomplished by using prototype-based objects TS classes may have properties methods and constructors Inheritance built in core language Uses extends keyword To call a method of a class, we have to create an instance of this class, with the new keyword Constructor • Named constructor(..) • Doesn’t return any values
  • 18. 18 Angular 9 Architecture Modules,Templates, MetaData, DataBinding, Directives,Services
  • 20. 20 Architecture - Modules 20 Angular apps are modular: • An application defines a set of Angular Modules or NgModules Every angular module is a class with an @NgModule decorator Every Angular App has at least one module: the root module NgModule takes a single metadata object describing the module, with the following properties • Declarations: view classes (components, directives and piped) • Exports: subset of public declarations, usable in the templates of other modules • Imports: external modules needed by the templates of this module • Providers: creators of services that this module contributes to • Bootstrap: main application view, called the root component, that hosts all other app views
  • 21. 21 Architecture Templates  A snippet of the HTML code of a component  A component's view is defined with its template  Uses Angular's template syntax, with custom elements
  • 22. 22 Architecture MetaData  Helps angular how to process data  Uses decorators to attach information to a class:  @Component  Selector : source of the base address (module.id) for module-relative URLs  TemplateUrl : address of the component's HTML template  Providers : : array of dependency injection providers for services that the component requires  StyleUrls : CSS address for the template code  Other metadata decorators: • @Injectable, @Input, @Output,.. 22
  • 23. 23 DataBinding  Mechanism for coordinating parts of a template with parts of a component  Four main forms  Interpolation {{...}} :  Displays the component's todo property value within the <td> element  Property Binding [….] :  Passes the value of id to the child comp  <view-todo>  Event Binding (click) :  Calls the component's updateTodo() method when the user clicks update button  Two-way data-binding [(ngModel)] :  Combines property and event binding, with ngModel 23
  • 24. 24 Directives  Angular templates are dynamic  When Angular renders them, it transforms the DOM according to instructions given by directives  A directive is a class with the @Directive decorator  A component is a directive-with-a-template  Two types of directives  Structural directives  Alter the layout by adding, removing and replacing elements in the DOM  <li *ngFor="let todo of todos"></li>  <view-todo *ngIf="idNotNull"> <view-todo>  Attribute directives  Alter the appearance or behaviour of an existant element  Look like regular HTML attributes  <input type='text' [(ngModel)] ="user.username"> 24
  • 25. 25 Architecture - Services 25 Service is a class with a narrow, well-defined purpose • Logging service, data service.. Component classes should be lean, • They shouldn't fetch data from the server, • They just deal with user experience, mediate between the view and the logic, • Everything non trivial should be delegated to services ng generate service <service-name> A service is associated to a component using dependency injection
  • 27. 27 Dependency Injection - Introduction Important design pattern Commonly called DI A way to supply a new instance of a class with the fully-formed dependencies it requires In plain English, one object supplying the dependencies of another object. Makes code more readable and maintainable. Most dependencies are services • DI is used to provide new components with the services they need • It knows which services to instantiate by looking at the types of the component's constructor parameters • constructor(private service : Service)
  • 28. 28 Injector  When Angular creates a component, it asks an injector for the services it requires  Component asks an injector for the services it requires  Maintains a container of service instances  If a requested service instance is not in the container, the injector makes one and adds it to the container before returning the service to Angular  When all requested services have been resolved and returned, Angular can call the component's constructor with those services as arguments Serive A Serice B Service C Component Constructor(private service : Service B) Inectors
  • 29. 29  Provider: Creates or returns a service  It is registered in a module or a component  Add it to the root module for it to be available everywhere  Register it in the component to get a new instance of the service with each new instance of the component  @NgModule(  { imports : [ ... ],  providers:[ TodoDataService, LogService ]  })  @Injectable() marks a class as available to an injector for instantiation  @Injectable({  providedIn: 'root',  })  Essential ingredient in every Angular service definition Dependency Injection Providers & @Injectable 29
  • 31. 31 Routing - Introduction  Enables navigation from one view to the next as users perform application tasks  Interprets a browser URL as an instruction to navigate to a clientgenerated view  Can pass optional parameters to the supporting view component to help it decide which specific content to display  Logs activity in the browser's history journal so the back and forward buttons work
  • 32. 32 Routing Module [ app-routing.module.ts ]  For simple routing, defining the routes in the main application module is fine  It can become more difficult to manage if the application grows and you use more Router features  Refactor the routing configuration in its own file: the Routing Module  The Routing Module  Separates routing concerns from other application concerns  Provides a module to replace or remove when testing the application  Provides a well-known location for routing service providers •  Does not declare components
  • 33. 33 Routing Module - Example  One singleton instance of the Router service exists for an application (app- routing.module.ts)  When the browser's URL changes, that router looks for the corresponding Route to know which component to display  A router has no routes until you configure it  In order to render the component chosen by the router, a router-outlet is inserted in the template RouterLink used to navigate between pages
  • 34. 34 RouterGuard Service  Sometimes, routes need to be protected: to prevent users from accessing, areas that they're not allowed to access, to ask for permission etc.,  Router Guards are applied to routes to do that  Four guard types:  CanActivate: decides if a route can be activated  CanActivateChild: decides if child routes of a route can be activated  CanDeactivate: decides if a route can be deactivated  CanLoad: decides if a module can be loaded lazily
  • 35. 35 Sites Additional References 1. https://angular.io/docs - Angular Documentation 2. https://www.typescriptlang.org/docs/home.html -TypeScript Docs 3. https://cli.angular.io/ - Angular commands Text books • The Ng-book - A Complete Book on Angular (2020 Edition) https://www.newline.co/ng-book/2/