Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,360 --> 00:00:03,450
Now though we've got some valid HDL on the screen.
2
00:00:03,460 --> 00:00:07,150
We need to start adding some actual interactions to each of these elements.
3
00:00:07,210 --> 00:00:11,800
So for example we need to make sure that whenever user changes the length right here we consider that
4
00:00:11,800 --> 00:00:14,170
length when we actually generate a password.
5
00:00:14,170 --> 00:00:17,130
Same thing for selecting or D selecting these checkboxes.
6
00:00:17,320 --> 00:00:21,430
And of course once the user clicks on the Generate button we need to actually generate a password and
7
00:00:21,430 --> 00:00:23,550
show it inside of that input.
8
00:00:23,620 --> 00:00:28,000
That's very clear at this point that we need to somehow deal with user interaction.
9
00:00:28,120 --> 00:00:30,350
And that's what we're going to figure out inside this video.
10
00:00:30,490 --> 00:00:35,920
How do we write some code to watch for a user changing that value or checking that checkbox or clicking
11
00:00:35,920 --> 00:00:39,840
that button to give ourselves a very easy straightforward target.
12
00:00:39,850 --> 00:00:44,470
We're going to first try to figure out how we can make sure that we just console log some kind of message
13
00:00:44,830 --> 00:00:47,110
anytime a user clicks on that button right there.
14
00:00:47,650 --> 00:00:53,210
That's the first thing we're going to figure out now as soon as we start talking about handling user
15
00:00:53,210 --> 00:00:53,990
input.
16
00:00:53,990 --> 00:00:57,560
You might think back to this diagram we looked back over here.
17
00:00:57,560 --> 00:01:03,590
Remember in this diagram we spoke about a very important type of file inside of angular projects a component
18
00:01:03,590 --> 00:01:09,800
class file and we had said that component class files contain code to run whenever important events
19
00:01:09,800 --> 00:01:13,030
occur like a user clicking a button.
20
00:01:13,030 --> 00:01:18,810
So as you'd guess we're going to find the component class file where our application right now that's
21
00:01:18,810 --> 00:01:21,620
going to be our app component dot t file.
22
00:01:21,780 --> 00:01:27,120
So we're going to find that file and inside that class we're going to add in some code to run whenever
23
00:01:27,230 --> 00:01:29,810
user clicks on that button.
24
00:01:29,810 --> 00:01:30,080
All right.
25
00:01:30,110 --> 00:01:35,890
So I'll go back over to my editor inside of my source app directory.
26
00:01:35,930 --> 00:01:39,350
I'm going to find the app component to yes file.
27
00:01:39,380 --> 00:01:43,750
Here is my component class now as we mentioned a couple of times.
28
00:01:43,750 --> 00:01:47,840
There is some crazy syntax inside of here that we're going to go over in due time.
29
00:01:47,960 --> 00:01:54,140
But right now let's just focus on all this button handling stuff inside the class app component.
30
00:01:54,150 --> 00:01:57,040
There's already one property at being initialized inside of here.
31
00:01:57,060 --> 00:02:00,590
So we're setting title equal to a string of P.W..
32
00:02:00,720 --> 00:02:03,060
This is some pre generated code right here.
33
00:02:03,060 --> 00:02:07,310
We're not actually using this property anymore so we're gonna delete it out of the class.
34
00:02:07,680 --> 00:02:12,480
We're then going to replace it with a function that is going to be called any time a user clicks on
35
00:02:12,480 --> 00:02:16,140
that button the inside of my app component class.
36
00:02:16,200 --> 00:02:18,540
I will write out on button
37
00:02:21,870 --> 00:02:27,720
and then inside of that function will add a simple console logs all say console log button was clicked
38
00:02:27,930 --> 00:02:30,380
like so OK.
39
00:02:30,410 --> 00:02:32,700
So we've now added some functionality to our class.
40
00:02:32,720 --> 00:02:38,300
We've added specifically a method that is going to be called anytime a user clicks on that button just
41
00:02:38,300 --> 00:02:41,650
adding the function itself doesn't actually do anything for us.
42
00:02:41,690 --> 00:02:46,940
We have to specifically tell angular that anytime someone clicks on that button we want to call this
43
00:02:46,940 --> 00:02:53,160
function right here the set up that mapping we need to add in some code to our template file.
44
00:02:53,220 --> 00:02:54,820
They're going to open up our template file.
45
00:02:54,860 --> 00:02:59,180
We're going to find that button we're going to add in a little piece of code to tell angular to call
46
00:02:59,180 --> 00:02:59,960
this function.
47
00:03:00,020 --> 00:03:08,840
Anytime user clicks on the button I will change back over to my app component each female file inside
48
00:03:08,840 --> 00:03:16,240
of you're going to scroll down until I find that button element here's the button right here with the
49
00:03:16,330 --> 00:03:21,040
very special syntax we're going to add into this button is not going to look like typical A.T.M. at
50
00:03:21,040 --> 00:03:21,600
all.
51
00:03:21,730 --> 00:03:27,730
It turns out that what we write inside this file is not strictly each team out it is technically a syntax
52
00:03:27,730 --> 00:03:29,840
called the angular template syntax.
53
00:03:30,010 --> 00:03:35,110
So we can write out what looks like normal H e-mail but there are also several other pieces of syntax
54
00:03:35,110 --> 00:03:36,070
that we can use.
55
00:03:36,070 --> 00:03:39,490
That is definitely not HCM L at all.
56
00:03:39,490 --> 00:03:44,650
This is going to be that first little piece of strange syntax so we start to see inside of the button
57
00:03:44,710 --> 00:03:45,820
element itself.
58
00:03:45,820 --> 00:03:51,670
I'm going to give myself a little bit of space here and then I'll put in a set of parentheses we put
59
00:03:51,670 --> 00:03:52,670
in a set of parentheses.
60
00:03:52,710 --> 00:03:58,390
Anytime you want to tell angular to watch for some kind of event to occur on this element inside those
61
00:03:58,390 --> 00:04:02,730
parentheses we're going to add in the name of the event that we want to watch for.
62
00:04:02,800 --> 00:04:10,120
So in this case I'm going to put in click after that all then put in an equal sign them double quotes
63
00:04:10,820 --> 00:04:16,150
and inside there we're going to try to call that function that we just wrote out over here called on
64
00:04:16,210 --> 00:04:25,090
button click I will type inside there on button click and I will call it like a function OK we're gonna
65
00:04:25,110 --> 00:04:26,930
pull this line apart very quickly.
66
00:04:26,940 --> 00:04:28,800
But first let's save this file.
67
00:04:28,800 --> 00:04:31,380
Go back over to our browser and test this out.
68
00:04:31,710 --> 00:04:34,680
We'll flip back over go back to my application.
69
00:04:34,740 --> 00:04:39,240
I'm going to open up my chrome console by right clicking anywhere on the screen and clicking inspect
70
00:04:40,250 --> 00:04:47,040
all then go to the console tab and then finally I'm going to click on the Generate button as soon as
71
00:04:47,040 --> 00:04:52,170
I do so I'll see that console log up here I can click it as many times I want and I keep getting additional
72
00:04:52,170 --> 00:04:54,280
console logs OK.
73
00:04:54,330 --> 00:04:56,550
So what's going on with that syntax.
74
00:04:56,550 --> 00:04:58,390
Well quick little diagram here.
75
00:04:58,760 --> 00:05:02,100
But this is what you're for too as the event binding syntax.
76
00:05:02,220 --> 00:05:04,070
We're going to write this out inside of a template.
77
00:05:04,160 --> 00:05:07,520
Anytime that we want to watch for some event that occurs to an element.
78
00:05:07,610 --> 00:05:12,210
So as I mentioned we're going to write in a set of parentheses inside the parentheses we're going to
79
00:05:12,210 --> 00:05:14,890
put the name of the event that we want to watch for.
80
00:05:15,150 --> 00:05:20,170
We can put in any standard H and vet event name inside there that we want.
81
00:05:20,190 --> 00:05:24,310
So for example we can have a mouse enter event or a mouse leave.
82
00:05:24,360 --> 00:05:25,530
We can have a drag event.
83
00:05:25,530 --> 00:05:31,680
We can have four inputs a change or an input event and so on all those standard h t mail events that
84
00:05:31,680 --> 00:05:32,830
are you are used to.
85
00:05:32,910 --> 00:05:36,340
Those names can go directly inside of your.
86
00:05:36,390 --> 00:05:41,900
Now here's the really confusing part about the event binding syntax whatever it goes inside of those
87
00:05:41,900 --> 00:05:48,740
double quotes right there is going to be evaluated as code when ever that event occurs.
88
00:05:48,800 --> 00:05:50,560
So whenever a user clicks on the button.
89
00:05:50,750 --> 00:05:58,150
This right here on button click that gets evaluated as though it were code that even though it really
90
00:05:58,150 --> 00:05:59,540
looks like a string to you and I.
91
00:05:59,590 --> 00:06:03,240
Not a string it is code though you're writing inside there.
92
00:06:03,280 --> 00:06:09,580
Now what is really interesting here is that calling on button click is going to automatically bind the
93
00:06:09,670 --> 00:06:15,690
on button click function that we defined inside of the component so this reference to on button click
94
00:06:15,690 --> 00:06:21,460
right here calls that method right there what is kind of surprising about this is that we did not have
95
00:06:21,460 --> 00:06:27,040
to write anything on here like say component dot on button click we didn't have to write that we did
96
00:06:27,040 --> 00:06:32,200
not have to write this dot on button click we didn't have to write app component on button click or
97
00:06:32,200 --> 00:06:33,250
anything.
98
00:06:33,250 --> 00:06:39,100
All we have to do is put in the name of the function on our class that we want to call whenever a user
99
00:06:39,100 --> 00:06:44,700
clicks a button that's it though this syntax right here with the double quotes where we have some code
100
00:06:44,820 --> 00:06:48,930
that is going to be kind of confusing when you're first going to use to angular or we're going to use
101
00:06:48,930 --> 00:06:51,500
this syntax so often that you're going to get used to it.
102
00:06:51,510 --> 00:06:53,540
Very quickly OK.
103
00:06:53,610 --> 00:06:57,740
So now that we've set up our first click event handler and we've had a very long discussion about it.
104
00:06:57,840 --> 00:06:58,640
Quick pause right here.
105
00:06:58,650 --> 00:07:01,560
We're going to continue to add in some more functionality in just a moment.
11206
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.