Function
on (eventNames, func) Function public
Module: | @ember/object |
---|
Defined in packages/@ember/-internals/metal/lib/events.ts:178
import { on } from '@ember/object/evented';
- eventNames
- String
- func
- Function
- returns
- Function
- the listener function, passed as last argument to on(...)
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/3.25/functions/@ember%2Fobject%2Fevented/on