Instructor: When you compile an Angular component, such as a reader component, into a web component, in a real world scenario, you obviously want to input some data and output some data from it. Let's quickly take a look how that would work.
From an Angular perspective, inputs are managed by that input decorator. Let's say, for instance, we get here an input name. We need to import that. We could say hi and name that gets passed to our component here. So far, that works perfectly.
Now, let's do the build compilation of our web component again. You can already see that it reflects your change. We could go over to our index HTML page and say something like that, name Yuri. When I save this, you can see how it perfectly works.
We can just pass it in via that name property here. Similarly, we can do this for the events. Here in the component, this is a normal output mapping. Let's call it greet, which is a new event emitter. You obviously need to import that event emitter here from Angular core.
In order to be able to trigger it, let's here add a button with the click event, doGreet. We also need to implement that accordingly in our component, where we simply then emit on our event emitter. We say here emit hi, this.name.
Great. We can now recompile our component, always using our script. Once that compilation finishes, we can again go to our index HTML file, and now react to that event.
Now, events are simply handled as you would normally do with DOM Elements. First of all, we need to grab an instance here of our DOM element. We use here the inaudible selector API of the browser, and we get here our doGreet.
Not add element, we say add event listener. We need to listen to our greet event, which is a custom event we just defined. We will here get the event object. First of all, let's simply log that out to the console to see what it looks like.
Let's go here to the console and click the greet button. You can see here, we get an instance of such a custom event. If you want to get the detail which we pass, it's directly inside that detail property. Here, we can see hi Yuri, which was the object which was triggered from the inside.
Here, we could simply say something like alert eve.detail. If you click, you can see how the message pops up directly. In this way, you can see how we can define inputs and outputs via those events.
Obviously, we could also specify the input directly here over at programmatic API. You see that will work as well.