SlideShare a Scribd company logo
1 of 33
Getting started with Angular
Workshop
Index
1. What is Typescript?
2. What is Angular?
3. Create Application
4. Project Structure
5. Building Blocks
6. Modules
7. Components
8. Templates
9. Directives
10. Routing
11. Quiz
What is Typescript?
What is Typescript?
● TypeScript is a superset of JavaScript
● It offers all of
JavaScript’s features + Type system.
● TypeScript is a free and open source
programming language.
● It is developed and maintained by Microsoft.
● Browsers can understand javascript but not
typescript. So, typescript code is first
compiled into javascript
● Language consists of language structures
like
○ Data Types, Custom Types
○ Modules
○ Class
○ Interface
○ Enums, etc.
Typescript to Javascript
(TSC)Typescript compiler converts ts code to js code
app.ts app.js
Typescript vs Javascript
Pros
● Early spotted bugs
● Predictability
● Readability
● Fast refactoring
● Rich IDE support
● Power of OOP
Cons
● Not true static typing
● More learning curve on top of
Javascript
● Adding extra step — transpiling
Typescript in action - Some quick examples
Typescript - Data Types
Typescript - Basic Data Types
● Boolean - let isDone: boolean = false;
● String - let color: string = "blue";
● Number - let decimal: number = 6;
● Array - let list: number[] = [1, 2, 3];
● Tuples - let x: [string, number] = ["hello", 10]
● Enum - enum Color { Red, Green, Blue }
● Unknown - let not Sure: unknown = 4;
● Type Alias/Interface - interface Todo { title: string; description: string; }
● Classes - class Rectangle { width: number; height: number; }
Common Typescript Language Features used in Angular
Defining & Exporting an interface
called Hero
Creating & Exporting a class that implements
an interface & has props and constructor.
Importing classes declared in another typescript file
What is Angular?
What is Angular?
● Angular is a single-page application framework
developed by Google
● It primarily serves as a TypeScript framework for
building user interfaces.
● It provides building blocks to help you quickly set up a
maintainable, scalable app.
Features & Benefits of Angular
Features & Benefits
● Full development Story - Basic Building
Blocks (Modules, Components, Directives,
Pipes, Routing, Forms, Http Networking, etc.),
Material UI, Animations, Testing, Accessibility,
Dev tools.
● Speed, Performance & Productivity - Code
Generation, Code Splitting, Angular CLI, IDEs
● Cross platform - Progressive Web Apps, Apps
that live on the web, mobile, or the desktop.
● Scalability
● Maintainability
● Modular development structure
● Extensive documentation and support
● Timely upgradations
● Huge Community
Tour of Heroes Application
Tour of Heroes Application
Create Application & Project Structure
Setup Angular
● Prerequisites : Node.js, npm package manager
● Install Angular CLI :
Create new Angular project
Serve your project
Angular - Building Blocks
Angular - Modules
Modules
● Modules are a great way to organize an
application and extend it with capabilities from
external libraries
● Angular libraries are NgModules, such as
RouterModule, FormsModule, HttpClientModule
● NgModules consolidate components, directives,
and pipes into cohesive blocks of functionality,
each focused on a feature area, application
business domain, workflow, or common collection
of utilities.
● Every Angular application has at least one module,
the root module.
● You bootstrap that module to launch the
application.
Angular - Modules
Decorator
@NgModule
Properties
● Declarations - The components, directives,
and pipes that belong to the NgModule.
● imports - Other NgModules you are using, so
that you can use their declarables
● Providers - Providers of services that
components in other NgModules can use
● Bootstrap - The entry component that Angular
creates and inserts into the index.html host
web page, thereby bootstrapping the
application.
Command
ng g m <module-name>
app.module.ts
Angular - Modules
Types
● Root Module
● Routing module
● Core Module
● Feature Module
● Shared Module, etc.
Angular - Components
Components
● Components are the main building block for Angular
applications.
● Each component consists of:
○ <component-name>.component.html - A html
template file, that declares what renders on the page
○ <component-name>.component.css - A CSS file
that contains the styling for the page.
○ <component-name>.component.ts - A typescript
file that contains class that defines the behaviour
○ <component-name>.component.spec.ts - A testing
specification file that defines the testing
specification for that page
Command
ng g c <component-name>
Ex: ng g c hero-list
Angular - Components
hero-list.component.ts
Decorator
@Component
Properties
● selector - ‘selector’ instructs
angular to instantiate this component
wherever it finds the corresponding
tag in template HTML
● templateUrl - Defines the template
file linked to this component
● styleUrls - Defines the style sheet
file linked to this component
Life Cycle
● ngOnInit - Called once when the
component is initialized
Tour of Heroes Application
app-root
app-hero-dashboard app-hero-detail app-hero-list
App Module
Angular - Template
Template
● A template is a chunk of HTML which renders a view, or
user interface, in the browser, just like regular HTML, but
with a lot more functionality.
● Each template in your application is a section of HTML to
include as a part of the page that the browser displays.
Binding
● A binding creates a live connection between a part of the
UI created from a template and the component instance
to which the template belongs
● This connection can be used to synchronize the view with
the component, to notify the component when an event or
user action takes place in the view, or both
Angular - Template
Text interpolation: Use interpolation to display the
value of this variable in the corresponding
component template.
SYNTAX : “{{variable_name}}”
Property binding: Setting an element property to a
component property value
SYNTAX : [element_property] = “variable_name”
Text Interpolation
Property binding
Angular - Template
Event binding: Event binding lets you listen for and
respond to user actions such as keystrokes, mouse
movements, clicks, and touches.
Event binding
Class binding: Use class to add and remove CSS class
names from an element's class attribute dynamically.
Class binding
Angular - Template
Two way binding: Two-way binding gives components in
your application a way to share data. Use two-way binding
to listen for events and update values simultaneously
between parent and child components.
Angular's two-way binding syntax is a combination of
square brackets and parentheses, [()].
Two way binding
Angular - Directives
Directives
● Directives are classes that add additional
behavior to elements in your Angular
applications.
● There are three type of directives in
Angular
○ Components
○ Structural
○ Attribute
● You can also create your own custom
attribute or structural directives
Structural
Change DOM by
adding/removing element.
Ex: *ngFor, *ngIf, *ngSwitch
Components
Directives with their own
templates .
Attribute
Change the behavior of HTML
elements, attributes,
properties, and components.
Ex: ngClass, ngStyle,
ngModel
Directives
Angular - Directives
Attribute
● Attribute directives listen to and modify the
behavior of other HTML elements, attributes,
properties, and components.
● Angular provides prebuilt attribute directives
such as
○ ngClass - Adds/removes a set of css
classes
○ ngStyle - Adds/removes a set of css styles
○ ngModel - Adds two way data binding to
an HTML form element
Angular - Directives
Structural
● Structural directives are directives which
change the DOM layout by adding and
removing DOM elements.
● You may apply only one structural directive to
an element.
● Angular provides a set of built-in structural
directives such as NgIf, NgForOf, NgSwitch and
others
● *ngFor - Used to repeat an element multiple
times
● *ngIf - Used to show an element conditionally.
● *ngSwitch - Used to show an element
conditionally.
‘div’ will get generated for each hero inside the heroes array
‘div’ will only get displayed if the hero value is non empty
Angular - Routing
app-routing.module.ts
Routing
● To handle the navigation from one view to the next,
you use the Angular Router
● When creating an angular application angular asks
whether routing is needed or not.
● If we allow it will create AppRoutingModule, which
is an NgModule where you can configure your
routes
app.component.html
Steps:
● Import RouterModule and Routes into your
routing module.
● Define your routes in your Routes array.
● Add your routes & router-outlet to your
application.
Angular - Routing
Eager loading
Loading Strategies
● Eager loading -
○ These route components are loaded when
the app launches in the browser.
○ The launch time will increase for large
applications if all routes are eager loaded
using this strategy
● Lazy loading -
○ These route components are loaded on
demand when the user navigates to these
components.
○ Optimizes the launch time.
Lazy loading
Quiz
1) TypeScript is a typed superset of JavaScript?
Yes No
2) Browsers can run typescript directly
Yes No
3) Angular is which type of framework?
SPA (Single Page Application) (MPA) Multi Page Application
4) Can you build cross platform app with Angular
No Yes
5) Every Angular application has at least one module
Yes (The root/app module) No
Quiz
6) To consolidate components, directives, and pipes into cohesive blocks of functionality, each
focused on a feature area what do we use in Angular?
Module Component
7) ________ in a Angular application is a section of HTML to include as a part of the page that the
browser displays.
Directive
8) For additional behavior to elements in your Angular applications what do you use?
Directive Routing
9) To Change DOM by adding/removing element you need
Attribute Directive (ngClass,ngModel) Structural Directive (*ngIf, *ngFor)
10) To optimize the loading time of your application you should use
Eager loading Lazy loading
Template
Any Questions?
Scan for Feedback

More Related Content

What's hot

State Machine Diagram
State Machine DiagramState Machine Diagram
State Machine Diagram
Niloy Rocker
 

What's hot (20)

Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Angular 14.pptx
Angular 14.pptxAngular 14.pptx
Angular 14.pptx
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
 
Angular Seminar-js
Angular Seminar-jsAngular Seminar-js
Angular Seminar-js
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
Flexbox and Grid Layout
Flexbox and Grid LayoutFlexbox and Grid Layout
Flexbox and Grid Layout
 
State Machine Diagram
State Machine DiagramState Machine Diagram
State Machine Diagram
 
Angular js
Angular jsAngular js
Angular js
 
Angular
AngularAngular
Angular
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
How To be a Backend developer
How To be a Backend developer    How To be a Backend developer
How To be a Backend developer
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Angular Observables & RxJS Introduction
Angular Observables & RxJS IntroductionAngular Observables & RxJS Introduction
Angular Observables & RxJS Introduction
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Xml
XmlXml
Xml
 

Similar to Foster - Getting started with Angular

4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 

Similar to Foster - Getting started with Angular (20)

How Does Angular Work?
How Does Angular Work?How Does Angular Work?
How Does Angular Work?
 
Angular.ppt
Angular.pptAngular.ppt
Angular.ppt
 
Angular crash course
Angular crash courseAngular crash course
Angular crash course
 
Introduction to Angular2
Introduction to Angular2Introduction to Angular2
Introduction to Angular2
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 
Angular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web ApplicationsAngular Best Practices To Build Clean and Performant Web Applications
Angular Best Practices To Build Clean and Performant Web Applications
 
Angular 9
Angular 9 Angular 9
Angular 9
 
Angular meetup 2 2019-08-29
Angular meetup 2   2019-08-29Angular meetup 2   2019-08-29
Angular meetup 2 2019-08-29
 
Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
 
Angular Interview Questions & Answers
Angular Interview Questions & AnswersAngular Interview Questions & Answers
Angular Interview Questions & Answers
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Angular patterns
Angular patternsAngular patterns
Angular patterns
 
Rise with angular
Rise with angularRise with angular
Rise with angular
 
Angular Basics.pptx
Angular Basics.pptxAngular Basics.pptx
Angular Basics.pptx
 
AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)
 
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
 
Angular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaAngular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad india
 
Start your journey with angular | Basic Angular
Start your journey with angular | Basic AngularStart your journey with angular | Basic Angular
Start your journey with angular | Basic Angular
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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...
 
"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 ...
 
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...
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 

Foster - Getting started with Angular

  • 1. Getting started with Angular Workshop
  • 2. Index 1. What is Typescript? 2. What is Angular? 3. Create Application 4. Project Structure 5. Building Blocks 6. Modules 7. Components 8. Templates 9. Directives 10. Routing 11. Quiz
  • 3. What is Typescript? What is Typescript? ● TypeScript is a superset of JavaScript ● It offers all of JavaScript’s features + Type system. ● TypeScript is a free and open source programming language. ● It is developed and maintained by Microsoft. ● Browsers can understand javascript but not typescript. So, typescript code is first compiled into javascript ● Language consists of language structures like ○ Data Types, Custom Types ○ Modules ○ Class ○ Interface ○ Enums, etc.
  • 4. Typescript to Javascript (TSC)Typescript compiler converts ts code to js code app.ts app.js
  • 5. Typescript vs Javascript Pros ● Early spotted bugs ● Predictability ● Readability ● Fast refactoring ● Rich IDE support ● Power of OOP Cons ● Not true static typing ● More learning curve on top of Javascript ● Adding extra step — transpiling
  • 6. Typescript in action - Some quick examples
  • 7. Typescript - Data Types Typescript - Basic Data Types ● Boolean - let isDone: boolean = false; ● String - let color: string = "blue"; ● Number - let decimal: number = 6; ● Array - let list: number[] = [1, 2, 3]; ● Tuples - let x: [string, number] = ["hello", 10] ● Enum - enum Color { Red, Green, Blue } ● Unknown - let not Sure: unknown = 4; ● Type Alias/Interface - interface Todo { title: string; description: string; } ● Classes - class Rectangle { width: number; height: number; }
  • 8. Common Typescript Language Features used in Angular Defining & Exporting an interface called Hero Creating & Exporting a class that implements an interface & has props and constructor. Importing classes declared in another typescript file
  • 9. What is Angular? What is Angular? ● Angular is a single-page application framework developed by Google ● It primarily serves as a TypeScript framework for building user interfaces. ● It provides building blocks to help you quickly set up a maintainable, scalable app.
  • 10. Features & Benefits of Angular Features & Benefits ● Full development Story - Basic Building Blocks (Modules, Components, Directives, Pipes, Routing, Forms, Http Networking, etc.), Material UI, Animations, Testing, Accessibility, Dev tools. ● Speed, Performance & Productivity - Code Generation, Code Splitting, Angular CLI, IDEs ● Cross platform - Progressive Web Apps, Apps that live on the web, mobile, or the desktop. ● Scalability ● Maintainability ● Modular development structure ● Extensive documentation and support ● Timely upgradations ● Huge Community
  • 11. Tour of Heroes Application
  • 12. Tour of Heroes Application
  • 13. Create Application & Project Structure Setup Angular ● Prerequisites : Node.js, npm package manager ● Install Angular CLI : Create new Angular project Serve your project
  • 15. Angular - Modules Modules ● Modules are a great way to organize an application and extend it with capabilities from external libraries ● Angular libraries are NgModules, such as RouterModule, FormsModule, HttpClientModule ● NgModules consolidate components, directives, and pipes into cohesive blocks of functionality, each focused on a feature area, application business domain, workflow, or common collection of utilities. ● Every Angular application has at least one module, the root module. ● You bootstrap that module to launch the application.
  • 16. Angular - Modules Decorator @NgModule Properties ● Declarations - The components, directives, and pipes that belong to the NgModule. ● imports - Other NgModules you are using, so that you can use their declarables ● Providers - Providers of services that components in other NgModules can use ● Bootstrap - The entry component that Angular creates and inserts into the index.html host web page, thereby bootstrapping the application. Command ng g m <module-name> app.module.ts
  • 17. Angular - Modules Types ● Root Module ● Routing module ● Core Module ● Feature Module ● Shared Module, etc.
  • 18. Angular - Components Components ● Components are the main building block for Angular applications. ● Each component consists of: ○ <component-name>.component.html - A html template file, that declares what renders on the page ○ <component-name>.component.css - A CSS file that contains the styling for the page. ○ <component-name>.component.ts - A typescript file that contains class that defines the behaviour ○ <component-name>.component.spec.ts - A testing specification file that defines the testing specification for that page Command ng g c <component-name> Ex: ng g c hero-list
  • 19. Angular - Components hero-list.component.ts Decorator @Component Properties ● selector - ‘selector’ instructs angular to instantiate this component wherever it finds the corresponding tag in template HTML ● templateUrl - Defines the template file linked to this component ● styleUrls - Defines the style sheet file linked to this component Life Cycle ● ngOnInit - Called once when the component is initialized
  • 20. Tour of Heroes Application app-root app-hero-dashboard app-hero-detail app-hero-list App Module
  • 21. Angular - Template Template ● A template is a chunk of HTML which renders a view, or user interface, in the browser, just like regular HTML, but with a lot more functionality. ● Each template in your application is a section of HTML to include as a part of the page that the browser displays. Binding ● A binding creates a live connection between a part of the UI created from a template and the component instance to which the template belongs ● This connection can be used to synchronize the view with the component, to notify the component when an event or user action takes place in the view, or both
  • 22. Angular - Template Text interpolation: Use interpolation to display the value of this variable in the corresponding component template. SYNTAX : “{{variable_name}}” Property binding: Setting an element property to a component property value SYNTAX : [element_property] = “variable_name” Text Interpolation Property binding
  • 23. Angular - Template Event binding: Event binding lets you listen for and respond to user actions such as keystrokes, mouse movements, clicks, and touches. Event binding Class binding: Use class to add and remove CSS class names from an element's class attribute dynamically. Class binding
  • 24. Angular - Template Two way binding: Two-way binding gives components in your application a way to share data. Use two-way binding to listen for events and update values simultaneously between parent and child components. Angular's two-way binding syntax is a combination of square brackets and parentheses, [()]. Two way binding
  • 25. Angular - Directives Directives ● Directives are classes that add additional behavior to elements in your Angular applications. ● There are three type of directives in Angular ○ Components ○ Structural ○ Attribute ● You can also create your own custom attribute or structural directives Structural Change DOM by adding/removing element. Ex: *ngFor, *ngIf, *ngSwitch Components Directives with their own templates . Attribute Change the behavior of HTML elements, attributes, properties, and components. Ex: ngClass, ngStyle, ngModel Directives
  • 26. Angular - Directives Attribute ● Attribute directives listen to and modify the behavior of other HTML elements, attributes, properties, and components. ● Angular provides prebuilt attribute directives such as ○ ngClass - Adds/removes a set of css classes ○ ngStyle - Adds/removes a set of css styles ○ ngModel - Adds two way data binding to an HTML form element
  • 27. Angular - Directives Structural ● Structural directives are directives which change the DOM layout by adding and removing DOM elements. ● You may apply only one structural directive to an element. ● Angular provides a set of built-in structural directives such as NgIf, NgForOf, NgSwitch and others ● *ngFor - Used to repeat an element multiple times ● *ngIf - Used to show an element conditionally. ● *ngSwitch - Used to show an element conditionally. ‘div’ will get generated for each hero inside the heroes array ‘div’ will only get displayed if the hero value is non empty
  • 28. Angular - Routing app-routing.module.ts Routing ● To handle the navigation from one view to the next, you use the Angular Router ● When creating an angular application angular asks whether routing is needed or not. ● If we allow it will create AppRoutingModule, which is an NgModule where you can configure your routes app.component.html Steps: ● Import RouterModule and Routes into your routing module. ● Define your routes in your Routes array. ● Add your routes & router-outlet to your application.
  • 29. Angular - Routing Eager loading Loading Strategies ● Eager loading - ○ These route components are loaded when the app launches in the browser. ○ The launch time will increase for large applications if all routes are eager loaded using this strategy ● Lazy loading - ○ These route components are loaded on demand when the user navigates to these components. ○ Optimizes the launch time. Lazy loading
  • 30. Quiz 1) TypeScript is a typed superset of JavaScript? Yes No 2) Browsers can run typescript directly Yes No 3) Angular is which type of framework? SPA (Single Page Application) (MPA) Multi Page Application 4) Can you build cross platform app with Angular No Yes 5) Every Angular application has at least one module Yes (The root/app module) No
  • 31. Quiz 6) To consolidate components, directives, and pipes into cohesive blocks of functionality, each focused on a feature area what do we use in Angular? Module Component 7) ________ in a Angular application is a section of HTML to include as a part of the page that the browser displays. Directive 8) For additional behavior to elements in your Angular applications what do you use? Directive Routing 9) To Change DOM by adding/removing element you need Attribute Directive (ngClass,ngModel) Structural Directive (*ngIf, *ngFor) 10) To optimize the loading time of your application you should use Eager loading Lazy loading Template

Editor's Notes

  1. https://stackblitz.com/run?file=src%2Fapp%2Fhero.service.ts
  2. https://stackblitz.com/run?file=src%2Fapp%2Fhero.service.ts
  3. https://stackblitz.com/run?file=src%2Fapp%2Fhero.service.ts