Topics for this chapter:
- Handling Browser Events
- Using Javascript controller file
The lightning framework uses event-driven programming model. We need to write handlers which respond to the event as they occur.
Events can be triggered by the user or can automatically be fired by the framework.
Browser events can be fired on user interaction with webpage like on click of a button or on drop-down value selection change.
You can declare these events in markup and handle in controller file.
A client-side controller handles events being fired by the component markup. It’s a JavaScript resource that defines the functions for all of the component’s actions.
Every method in the controller file accepts three parameters which are being supplied by the framework itself. These parameters are:
component—The component to which the controller belongs.
event—The event that the action is handling.
helper—The component’s helper. A helper contains functions that can be reused by any JavaScript code in the component bundle.
Put functions that you want to reuse in the component’s helper.js. These functions can be called from multiple controller/helper functions.
Helper file helps in moving heavy lifting from the client-side controller. Helper functions also enable specialization of tasks, such as processing data and firing server-side actions.
Helper methods cannot be called directly from component markup and must be invoked from controller, renderer or helper file.
Component File
https://gist.github.com/3e2ec651690a0ccf41dc7a00afe06c12Controller File
https://gist.github.com/560c062b27f898fbb80782f6d75ac0fcLightning Component Development Day3 - App, Attributes, Looping, Conditional Markup, Handling Events
Handling Browser Events In Javascript Controller
Question
Your answer:
Correct answer:
Your Answers