In this video, Emmanuel Henri explains what actions are and how they can be used in the HTML and the controllers.
- [Instructor] Again, using the same example files…from the final project n0403, next item,…what we need to do events with Stimulus are actions.…Actions react to DOM events; therefore, when we click…on something, or when a specific event happens,…run this code into our controller.…The syntax of an action is similar to what we've done…thus far to add an attribute to the element…that will initiate the event, or action,…with the syntax data-action, like so here.…
So if we look at the button here, we have a data-action,…and then we have a click event, which will resolve…in running the greet function inside of the card controller.…So basically, click, then look into the card controller…for our greet function, simple as this.…So the button initiates the action, the action calls…the method into our controller class,…and boom, we've got the results.…
So if we go into the card controller, we have this function…that will run as soon as we click on that button.…All right, in the next video let's practice all this.…Targets and actions and adding and put into our application…
- Why use Stimulus?
- Adding and using controllers
- The role of identifiers
- Using targets and actions
- Working with the state in Stimulus
- Persisting the state in the DOM