Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,340 --> 00:00:04,130
Our card component is now visible on the screen which is great.
2
00:00:04,160 --> 00:00:09,240
But in this video I want to give you a little bit deeper understanding of exactly what is going on.
3
00:00:09,350 --> 00:00:14,720
In particular I want to help you understand how angular actually takes that app Card element that we
4
00:00:14,720 --> 00:00:21,680
placed inside that HDL file right here and it makes a instance of the card component and displays it
5
00:00:21,710 --> 00:00:22,870
on the screen.
6
00:00:22,870 --> 00:00:27,020
So in this video we're going to go through one or two quick diagrams that's going to give you a better
7
00:00:27,020 --> 00:00:32,210
understanding of how angular actually boots up our application in the browser and eventually displays
8
00:00:32,240 --> 00:00:34,890
an instance of the card component right there.
9
00:00:34,910 --> 00:00:35,140
All right.
10
00:00:35,150 --> 00:00:39,110
So the first diagram we're going to look at is going to look completely unrelated but trust me this
11
00:00:39,170 --> 00:00:40,610
all ties together.
12
00:00:40,870 --> 00:00:45,580
This is what happens when we first tried to access our application inside the browser.
13
00:00:45,590 --> 00:00:48,500
You and I open up a new browser window and we type into it.
14
00:00:48,500 --> 00:00:51,200
Local host colon forty two hundred.
15
00:00:51,230 --> 00:00:57,440
When we hit the enter key our browser is going to issue an H TTP request to our angular development
16
00:00:57,440 --> 00:00:58,430
server.
17
00:00:58,430 --> 00:01:01,850
Remember our angular development server is running on our local machine.
18
00:01:01,940 --> 00:01:07,430
That is the program that you and I are starting up when we run and G starts or excuse me AMG serve or
19
00:01:07,430 --> 00:01:13,210
NPM start at our terminal that we make an initial h t keep your quest over to that server.
20
00:01:13,210 --> 00:01:18,520
The angular development server then always responds by first sending us a file called the Index dot
21
00:01:18,540 --> 00:01:20,350
h t email file.
22
00:01:20,350 --> 00:01:24,240
This is a file that actually exists inside of our project directory right now.
23
00:01:24,310 --> 00:01:30,860
So if we go back over to our Ed and look inside the s RC directory you'll see a file inside there called
24
00:01:31,010 --> 00:01:32,220
index dot HDMI out.
25
00:01:32,300 --> 00:01:37,950
So again first thing that gets sent to our browser when we're trying to access our application.
26
00:01:38,010 --> 00:01:42,110
Now when you look at this file one thing that you might notice right away is that there are no script
27
00:01:42,110 --> 00:01:43,190
tags inside of it.
28
00:01:43,610 --> 00:01:48,310
So it kind of appears as though we are never actually loading up any javascript code.
29
00:01:48,320 --> 00:01:53,060
Well if you go back over to our application site the browser really quickly and open up your element
30
00:01:53,090 --> 00:01:56,450
Inspector here's my element Inspector.
31
00:01:56,620 --> 00:02:02,080
You'll notice that there actually are a series of script tags inside of here it turns out that our angular
32
00:02:02,080 --> 00:02:07,330
development server before sending the contents of this file down to the browser it is going to automatically
33
00:02:07,330 --> 00:02:12,100
add a couple of script tags to the very bottom of that body element right there.
34
00:02:12,130 --> 00:02:19,360
That is how we eventually get some javascript script tags added inside of here but that resulting file
35
00:02:19,420 --> 00:02:23,500
finally gets sent down to the browser the browser is going to see all the script tags and then make
36
00:02:23,500 --> 00:02:28,460
some follow up requests to the development server to get access to all those scripts.
37
00:02:28,520 --> 00:02:34,330
And so our server is going to send down all that JavaScript which gets executed inside the browser now
38
00:02:34,390 --> 00:02:37,300
as soon as our browser starts to load all those different files.
39
00:02:37,330 --> 00:02:43,470
It's going to take a look at each the different components that we have declared in particular.
40
00:02:43,630 --> 00:02:50,800
It's going to look at the component class files but that is our art dot component dot T.S. file and
41
00:02:50,800 --> 00:02:53,600
our app dot component dot t s file.
42
00:02:53,620 --> 00:02:58,510
Now as I mentioned just a moment ago both of these files of this little thing at the top right here
43
00:02:58,870 --> 00:03:02,790
a little bit of typescript called a decorator inside the decorator.
44
00:03:02,830 --> 00:03:08,680
We've got that selector property whenever angular sees this selector thing right here and makes a little
45
00:03:08,710 --> 00:03:15,700
mental note and it says hey well a selector anytime I see an HMO element with that a little element
46
00:03:15,700 --> 00:03:21,820
name right there going to create a new instance of this component and show it in the DOM at this point.
47
00:03:21,820 --> 00:03:23,940
Things are getting just a little bit complicated.
48
00:03:23,950 --> 00:03:28,000
Let's take a look at a flow diagram that's going to breakdown those last couple of things I mentioned
49
00:03:28,300 --> 00:03:31,850
into a series of discrete steps all right.
50
00:03:31,880 --> 00:03:32,660
So here's our diagram
51
00:03:35,630 --> 00:03:35,890
okay.
52
00:03:35,960 --> 00:03:37,660
We're gonna go through this step by step.
53
00:03:37,700 --> 00:03:41,120
There's a couple of steps here but they're mostly repetitive so we're going to go through it rather
54
00:03:41,120 --> 00:03:46,210
quickly though angular is going to load up each of those different component class files and it's going
55
00:03:46,220 --> 00:03:48,680
to take a look at that selector property.
56
00:03:48,860 --> 00:03:50,080
Here's the key part.
57
00:03:50,300 --> 00:03:56,240
We first need to have some kind of root component that gets displayed in the DOM though when angular
58
00:03:56,240 --> 00:04:01,520
first loads up inside the browser it's going to take a look at the H team l document that was sent down
59
00:04:01,520 --> 00:04:03,200
to the browser itself.
60
00:04:03,200 --> 00:04:10,060
If we go back to that indexed on each e-mail file right here you'll notice that inside the body there
61
00:04:10,060 --> 00:04:16,810
is an app dash root element that is a little sign to angular that we want to show our app component.
62
00:04:16,810 --> 00:04:21,820
If you go back to the app component dot t s file you'll notice that the selector for that one is app
63
00:04:21,820 --> 00:04:23,090
dash route.
64
00:04:23,200 --> 00:04:28,330
So as soon as angular sees that it's going to try to find a matching component inside an application
65
00:04:28,720 --> 00:04:34,900
with the selector of app dash route the angular finds the app component and then creates an instance
66
00:04:34,990 --> 00:04:36,570
of that component.
67
00:04:36,580 --> 00:04:40,000
Remember in JavaScript we've got the idea of classes.
68
00:04:40,030 --> 00:04:41,840
Classes are like a blueprint.
69
00:04:41,980 --> 00:04:43,510
We don't ever use a class directly.
70
00:04:43,510 --> 00:04:46,550
Instead we create instances out of those classes.
71
00:04:46,830 --> 00:04:52,000
The angular is going to create an instance of that app component class angular is then going to take
72
00:04:52,060 --> 00:04:53,440
a look at that instance.
73
00:04:53,440 --> 00:04:56,070
That's going to take a look at the accompanying template file.
74
00:04:56,270 --> 00:05:00,140
It's going to pass the template file and turn it all into real H2.
75
00:05:00,910 --> 00:05:07,320
It's going to take all that HMO and stick it directly into the app dash route element that it had found.
76
00:05:07,510 --> 00:05:12,220
We refer to that app dash route element or the element that's kind of containing all the output of the
77
00:05:12,340 --> 00:05:15,370
component template as a host element.
78
00:05:15,430 --> 00:05:17,950
We can actually see this very easily inside the browser.
79
00:05:18,030 --> 00:05:23,290
So if you go back over to our application you'll notice that inside of our Dom we've got that app dash
80
00:05:23,290 --> 00:05:24,230
route element.
81
00:05:24,410 --> 00:05:30,560
If we expand it we'll see everything that makes up our actual each CML for the template.
82
00:05:30,610 --> 00:05:32,730
So again we referred to app Astra right here.
83
00:05:32,740 --> 00:05:36,760
That is our host element.
84
00:05:36,940 --> 00:05:42,590
Then while throwing all the contents of that template into the DOM angular next sees that inside there
85
00:05:42,710 --> 00:05:48,740
is an element called app dash cart typically that one right there the once again angular is going to
86
00:05:48,740 --> 00:05:52,580
take a look at all of the different components inside of our application.
87
00:05:52,580 --> 00:05:56,070
That's going to find one with a selector of app dash cart.
88
00:05:56,150 --> 00:06:03,680
In this case it finds our hard component to yes file it right here as it has a matching selector so
89
00:06:03,890 --> 00:06:09,260
angular will then create an instance out of that card component and then the entire process is going
90
00:06:09,260 --> 00:06:11,080
to repeat itself again.
91
00:06:11,270 --> 00:06:15,590
Angular is going to take that instances template it's going to turn it into real HDL and then it's going
92
00:06:15,590 --> 00:06:21,050
to stick it into the app card element which once again we refer to as the host element.
93
00:06:21,050 --> 00:06:25,130
And once again we can see that directly in the DOM but there's the app dash card right there.
94
00:06:25,220 --> 00:06:30,240
And if we expand that element we'll see inside there is the paragraph element.
95
00:06:30,540 --> 00:06:30,810
OK.
96
00:06:30,820 --> 00:06:32,810
So that is what is going on behind the scenes.
97
00:06:32,840 --> 00:06:36,470
It is a recursive process angular loads up.
98
00:06:36,510 --> 00:06:41,610
It finds all these different elements with special names it sees if it has a matching component with
99
00:06:41,610 --> 00:06:46,560
a matching selector if it does it's going to create an instance out of that component render the template
100
00:06:46,740 --> 00:06:52,530
and stick all the resulting H2 UML into that host element and then it just repeats that process over
101
00:06:52,530 --> 00:06:55,520
and over and over again OK.
102
00:06:55,550 --> 00:06:56,560
So now you've seen this.
103
00:06:56,560 --> 00:07:00,590
Well let's take another pause right here and continue working on our application in just a moment.
11241
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.