When creating components, you can attach events to them. Let's take a look at an example of this.
In a new project, generate a new component called
student-info
:$ ember g component student-info
This will generate a component file in the
component
directory and thetemplates/components
folder.Edit the
app/components/student-info.js
file. Add a newclick
event:// app/components/student-info.js import Ember from 'ember'; const {$}= Ember export default Ember.Component.extend({ click() { $('html').fadeToggle( 'slow', 'linear'); $('html').delay(250).fadeIn(); } });
The first thing that you'll notice in this example is that we are using the ES2015 destructuring assignment. The destructuring assignment syntax extracts data from arrays or objects. Instead of typing
Ember.$
everywhere, I can just type$
.Ember CLI by default has jQuery installed. We are using the jQuery syntax to fade the HTML document and fade it back after the component...