Function
on (eventNames, func) public
Module: | @ember/object |
---|
Defined in packages/ember-metal/lib/events.js:248
import { on } from '@ember/object/evented';
- eventNames
- String
- func
- Function
- returns
- func
Define a property as a function that should be executed when a specified event or events are triggered.
import EmberObject from '@ember/object';
import { on } from '@ember/object/evented';
import { sendEvent } from '@ember/object/events';
let Job = EmberObject.extend({
logCompleted: on('completed', function() {
console.log('Job completed!');
})
});
let job = Job.create();
sendEvent(job, 'completed'); // Logs 'Job completed!'
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/2.18/functions/@ember%2Fobject%2Fevented/on