Week 2 Angular Typescript
Week 2 Angular Typescript
Development
(CSE-214)
week-2 : Angular - Typescript
1
What is Angular ?
2
What is Single Page Application ?
3
What is Single Page Application ?
• Single-Page Applications (SPAs) are web apps that load all the
necessary HTML, CSS, and JavaScript in the initial page load, and
then dynamically update their Document Object Model (DOM)
and retrieve extra data based on user interactions.
4
What is Document Object Model (DOM) ?
5
What is Document Object Model (DOM) ?
6
What is Document Object Model (DOM) ?
9
JavaScript Code for Hierarchical DOM Traversal
10
JavaScript Code for Hierarchical DOM Traversal
JavaScript function that hierarchically traverses the DOM tree and logs each
node’s structure: (1) Starts at document.body and recursively traverses all child
elements. (2) Indents nodes based on their depth level in the tree. (3) Prints the
node name in the console in a hierarchical format.
11
DOM Manipulation Using var
12
var is function-scoped (NOT block-scoped)
Variables declared with var inside a function are accessible throughout the entire
function, but not outside of it.
13
var is hoisted but initialized as undefined
14
Global Scope Pollution: var can leak into the
global scope
If var is declared inside a function without using var inside another function, it
can accidentally become a global variable.
15
What is Single Page Application ?
16
What is Single Page Application ?
17
What is Single Page Application ?
19
Traditional Application
• In the pre-SPA days, a user would visit a URL in a browser and request one HTML
file and all its associated HTML, CSS, and JavaScript files from a web server.
• After some network delay, the user sees the rendered HTML in the browser (client)
and starts to interact with it.
• If your website is complex, the site browsing experience may appear slow to
users. It will be even slower if they have a poor or limited internet connection.
• To solve this problem, many web developers build their web applications as SPAs.
20
Single-Page Application
21
Single Page Application
22
Single Page Application
23
Traditional Application
24
Angular Solution
25
Angular History
26
Angular History + Future
27
Angular
28
Angular
29
Angular Development Tools
30
Command-Line Tools
31
MS Windows - Install Development Tools
32
TypeScript Basics
33
Angular Development
34
Angular Development
35
TypeScript
36
Troubleshooting
37
Troubleshooting
38
TypeScript
39
TypeScript
40
TypeScript
41
TypeScript
42
TypeScript
43
TypeScript
44
TypeScript Variables
45
Define Variables
46
Examples
47
Examples
48
TypeScript: "let" keyword
49
Difference Between let and var in JavaScript
The let and var keywords are used to declare variables in JavaScript, but they
behave differently in terms of scoping, hoisting, and redeclaration
50
Scope Issue (Function vs. Block Scope)
var declarations are hoisted, but their values are set to undefined until assignment.
let is also hoisted, but accessing it before initialization results in an error
52
Capturing in Loops (var Pitfall)
var does not create a new variable for each iteration of a loop.
It captures the last value, causing unexpected behavior in asynchronous code.
Fix with let (Creates a New Variable in Each Iteration)
53
asynchronous code
55
TypeScript is Strongly Typed
56
Type: any
57
Displaying Output
58
Run the App
59
Template Strings
60
For Loops
61
For Loop - Array of numbers
62
Simplified For Loop
63
Conditionals
64
Growable Arrays
65
Creating Classes
66
Basic Class Structure
67
Properties
68
Construct an Instance
69
Create a Constructor
70
Construct an Instance
71
Access Modifiers
72
Mark the properties as "private"
73
Compiling the Code
74
Compiling the Code
75
Compiling the Code
76
Compiling the Code
77
Class
78
Getter / Setter Methods
79
Getter / Setter Methods
80
Getter / Setter Methods
81
TypeScript: Accessors - Get / Set
82
TypeScript: Accessors - Get / Set
83
TypeScript: Accessors - Get / Set
84
Compiler flag
85
Problem with too many compiler flag
86
tsconfig.json
87
tsconfig.json
88
Compiling your Project
89
TypeScript: Accessors - Get / Set
90
Parameter Properties
91
Constructor - Traditional Approach
92
Constructor - Parameter Properties
93
Parameter Properties - In Action
94
Parameter Properties - In Action
95
Code Organization
96
TypeScript Modules
97
TypeScript Modules
98
Module Example
99
Module Example
100
Inheritance
101
Inheritance Example
102
Inheritance Example
103
Creating a main app
104
Rectangle
105
Creating a main app
106
Creating an Array of Shapes
107
Abstract Class
108
Abstract Class Example
109
Abstract Class Example
110
Circle
111
Creating an Instance
112
Creating an Array of Shapes
113
Interfaces
114
Interface Example
115
Interface Example
116
Creating a Main App
117
Creating an Array of Coaches
118
interfaces and abstract classes: Key
Differences
In Angular (TypeScript), both interfaces and abstract classes help define the
structure of objects, but they serve different purposes and have key differences.
119
interfaces and abstract classes: Key
Differences
Use an Interface when you just need to define a contract/shape for objects.
Use an Abstract Class when you want to provide a base class with some shared
implementation and enforce method overriding.
120