Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,920 --> 00:00:05,600
We now have the ability to get some kind of notification anytime a user clicks on that button inside
2
00:00:05,600 --> 00:00:06,830
of our template.
3
00:00:06,830 --> 00:00:11,690
Now we're going to try to reverse that behavior rather than having our template tell us that something
4
00:00:11,690 --> 00:00:12,590
just occurred.
5
00:00:12,620 --> 00:00:18,320
We're gonna figure out how to stuff information into our template so in particular we're gonna make
6
00:00:18,320 --> 00:00:22,760
sure that whenever user clicks on this button rather than doing a console log we're going to try to
7
00:00:22,820 --> 00:00:25,440
update the value of this input right here.
8
00:00:25,470 --> 00:00:29,750
That's going to be very close to the behavior that we need for the final version of our application
9
00:00:29,750 --> 00:00:34,490
because remember the end goal is whenever user clicks on this button we show some randomly generated
10
00:00:34,490 --> 00:00:35,600
password in there.
11
00:00:35,690 --> 00:00:37,790
We're not going to randomly generate the password just yet.
12
00:00:37,790 --> 00:00:39,990
That's something we'll figure out down the line.
13
00:00:40,200 --> 00:00:43,910
So let's figure out how to do this before we start to add in any code.
14
00:00:43,910 --> 00:00:49,190
I want to give you a very quick reminder on how input elements in normal HDL work.
15
00:00:49,190 --> 00:00:55,450
In general I've got a very small code snippet over here just to jog your memory on the top left inside.
16
00:00:55,460 --> 00:00:57,600
I've got a very small snippet of each CML.
17
00:00:57,650 --> 00:01:03,630
And then on the right hand side is a preview of what that H2 looks like if we show an input element
18
00:01:03,930 --> 00:01:08,680
and we give it a value attribute this is referred to as an attribute right here.
19
00:01:08,880 --> 00:01:14,130
And whenever the input is displayed on the screen the initial starting value of that input is going
20
00:01:14,130 --> 00:01:21,090
to be set equal to a SDF but other words if we set the value attribute that's going to initialize the
21
00:01:21,090 --> 00:01:24,570
value of the input okay.
22
00:01:24,600 --> 00:01:30,130
So with then mind let's go back over to our code editor and start writing out some code.
23
00:01:30,140 --> 00:01:30,410
All right.
24
00:01:30,440 --> 00:01:34,920
I'm going to first begin inside of my app component class file inside of here.
25
00:01:34,940 --> 00:01:40,800
We're going to set up a new property inside of our class so at the very top of the class I'm going to
26
00:01:40,800 --> 00:01:46,640
write out password equals empty string like so.
27
00:01:46,670 --> 00:01:50,510
Now if you're not familiar with the syntax inside of a class that is totally okay.
28
00:01:50,600 --> 00:01:56,270
What we have right here is 100 percent equivalent to defining a constructor function and saying this
29
00:01:56,270 --> 00:01:57,880
dot password is empty string.
30
00:01:57,890 --> 00:02:02,780
Inside there though all this line right here does is say that whenever we create a new instance of this
31
00:02:02,780 --> 00:02:11,080
class it is going to add a password property and it's going to start off as an empty string then whenever
32
00:02:11,080 --> 00:02:15,970
user clicks on our button rather than doing the console log we're going to update the value of that
33
00:02:15,970 --> 00:02:19,040
password property bungling to remove the console log.
34
00:02:19,080 --> 00:02:22,820
They'll say this dot password is some random string instead.
35
00:02:22,840 --> 00:02:26,110
So I'll put in something like about my password
36
00:02:29,040 --> 00:02:29,470
all right.
37
00:02:29,620 --> 00:02:33,690
Now at this point time I want you to just look at this class by itself.
38
00:02:33,760 --> 00:02:36,520
Don't worry about any of the other special syntax inside of here.
39
00:02:36,580 --> 00:02:38,470
Don't worry about the fact that we're using angular.
40
00:02:38,470 --> 00:02:40,810
Just look at the class.
41
00:02:40,810 --> 00:02:44,390
The class by itself is really simple and straightforward in nature.
42
00:02:44,440 --> 00:02:47,220
The class has one property outward.
43
00:02:47,320 --> 00:02:50,820
When we first create an instance of this class password is an empty string.
44
00:02:50,980 --> 00:02:54,840
And then if we ever call this method right here we're going to update the value of password.
45
00:02:55,030 --> 00:02:56,610
That is it the by itself.
46
00:02:56,620 --> 00:02:59,980
The class is very simple and straightforward in nature.
47
00:02:59,980 --> 00:03:02,940
Now here's where things start to get a little bit more complicated.
48
00:03:02,980 --> 00:03:08,620
We now need to make sure that we somehow take this password property and throw it into our template
49
00:03:10,320 --> 00:03:13,710
but to do so we'll go back over to our template file.
50
00:03:13,880 --> 00:03:16,170
We're going to find the input at the very bottom.
51
00:03:16,190 --> 00:03:22,310
So this is where we display the generated password and then we're going to set the input or simply the
52
00:03:22,310 --> 00:03:24,440
value property on this input right here.
53
00:03:24,740 --> 00:03:31,100
So this is going to be very close to what you see back over here though on the input element inside
54
00:03:31,100 --> 00:03:33,380
of a set of square brackets.
55
00:03:33,380 --> 00:03:38,200
We're going to put in value well then put down equals.
56
00:03:38,490 --> 00:03:44,240
And then inside of double quotes once again we'll write out password all right.
57
00:03:44,250 --> 00:03:46,470
So rather than discuss what's going on here.
58
00:03:46,500 --> 00:03:49,060
Let's once again just save this file.
59
00:03:49,080 --> 00:03:54,880
Well you will go back over to our application now click on the Generate button and I'll see the text
60
00:03:54,940 --> 00:03:57,600
my password appear inside there.
61
00:03:57,610 --> 00:03:58,960
It's clear that this works.
62
00:03:58,960 --> 00:04:01,940
But let's understand why it works.
63
00:04:01,960 --> 00:04:05,280
First off let's review the syntax right here on that input element.
64
00:04:05,320 --> 00:04:07,590
So quick diagram once again.
65
00:04:07,780 --> 00:04:11,490
This is what we refer to as the property binding syntax.
66
00:04:11,600 --> 00:04:14,700
So we put down a set of square brackets inside there.
67
00:04:14,710 --> 00:04:20,220
We put in the name of the property that we want to set on that element in this case.
68
00:04:20,220 --> 00:04:25,490
We want to set the value property then inside of a set of double quotes.
69
00:04:25,600 --> 00:04:30,940
We put down a expression to say what value we want to stick inside there.
70
00:04:31,090 --> 00:04:37,120
Just like we saw back with that event finding stuff whenever we put inside of here is evaluated as code.
71
00:04:37,120 --> 00:04:39,580
So that is not a string that says password.
72
00:04:39,580 --> 00:04:44,590
That is some javascript code technically typescript at this point but we're just going to say it is
73
00:04:44,590 --> 00:04:50,320
code and it gets evaluated as code so even though it really looks like we are saying put the string
74
00:04:50,380 --> 00:04:53,720
of password inside of that input that is not the case.
75
00:04:53,860 --> 00:04:59,980
This means take a look at our component class instance take a look at its password property though this
76
00:04:59,980 --> 00:05:01,110
one right here.
77
00:05:01,260 --> 00:05:09,350
And whatever that property value is take it in as the actual value for this input and the really important
78
00:05:09,350 --> 00:05:15,500
thing here to also understand is that whenever the password property on the class changes angular automatically
79
00:05:15,500 --> 00:05:21,290
detects that and it's going to automatically take the updated password property and throw it in as the
80
00:05:21,290 --> 00:05:23,260
new value to our input.
81
00:05:23,300 --> 00:05:24,890
There's a little bit of magic there.
82
00:05:24,890 --> 00:05:30,480
Without a doubt it just you know once again we did not have to write on password there we didn't have
83
00:05:30,480 --> 00:05:35,280
to say this dot password we didn't have to say component dot password we didn't have to say app component
84
00:05:35,280 --> 00:05:42,610
dot password or anything like that we just put the name of the property from our class and poof it appeared.
85
00:05:42,740 --> 00:05:44,030
And one last thing I want to show you.
86
00:05:44,670 --> 00:05:49,290
Rather than putting a property name right there we could just as easily tried to call a method that
87
00:05:49,290 --> 00:05:52,740
would return the property we want to stick in instead.
88
00:05:52,740 --> 00:05:59,880
So for example if we go back over to app component we added in a new method called Get password and
89
00:05:59,890 --> 00:06:06,730
inside there if we said return the stop password we can now try to call this method when getting our
90
00:06:06,730 --> 00:06:09,060
password and sticking it into the template over here.
91
00:06:09,510 --> 00:06:16,170
So instead of just referencing the property name password we could call the get password method let's
92
00:06:16,170 --> 00:06:21,980
try saving that as well I'll hit generate and I still see the correct thing.
93
00:06:21,980 --> 00:06:27,000
Show up OK so we've now seen how to set up an event handler.
94
00:06:27,010 --> 00:06:32,100
We've also seen how to set up a property that gets bounced to our class every very last thing.
95
00:06:32,110 --> 00:06:33,920
I'm going to undo that last change.
96
00:06:33,970 --> 00:06:38,140
I just want you to know that we could put in any property name or method name inside there.
97
00:06:38,140 --> 00:06:43,920
So I am going to revert that back to password and I'm going to remove the get password method from the
98
00:06:43,920 --> 00:06:44,790
class as well.
99
00:06:46,530 --> 00:06:50,940
So quick pause now that we've seen and how to get information into the template and out of it.
100
00:06:50,940 --> 00:06:53,710
Well let's continue working on our application in just a moment.
10718
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.