home
  • Blog
  • Home
  • Projects
    • Ember
    • EmberData
    • Ember CLI
2.18
  • Packages
    • @ember/application
    • @ember/array
    • @ember/component
    • @ember/controller
    • @ember/debug
    • @ember/engine
    • @ember/error
    • @ember/object
    • @ember/polyfills
    • @ember/routing
    • @ember/runloop
    • @ember/service
    • @ember/string
    • @ember/test
    • @ember/utils
    • ember-glimmer
    • jquery
  • Classes
    • Adapter
    • Application
    • ApplicationInstance
    • ApplicationInstance.BootOptions
    • ArrayProxy
    • Checkbox
    • Component
    • ComputedProperty
    • ContainerDebugAdapter
    • ContainerProxyMixin
    • Controller
    • CoreObject
    • DataAdapter
    • Ember.Debug
    • Ember.Logger
    • Ember.MutableEnumerable
    • Ember.Namespace
    • Ember.NativeArray
    • Ember.Templates.helpers
    • Ember.Test
    • Ember.Test.QUnitAdapter
    • EmberArray
    • EmberError
    • EmberObject
    • Engine
    • EngineInstance
    • Evented
    • GlobalsResolver
    • HashLocation
    • Helper
    • HistoryLocation
    • LinkComponent
    • Mixin
    • MutableArray
    • NoneLocation
    • ObjectProxy
    • Observable
    • PromiseProxyMixin
    • RSVP.EventTarget
    • RSVP.Promise
    • Route
    • Router
    • RouterService
    • Service
    • String
    • TextArea
    • TextField

Class Evented public


Defined in: packages/ember-runtime/lib/mixins/evented.js:13
Module: @ember/object
import Evented from '@ember/object/evented';

This mixin allows for Ember objects to subscribe to and emit events.

app/utils/person.js
import EmberObject from '@ember/object';
import Evented from '@ember/object/evented';

export default EmberObject.extend(Evented, {
  greet() {
    // ...
    this.trigger('greet');
  }
});
var person = Person.create();

person.on('greet', function() {
  console.log('Our person has greeted');
});

person.greet();

// outputs: 'Our person has greeted'

You can also chain multiple event subscriptions:

person.on('greet', function() {
  console.log('Our person has greeted');
}).one('greet', function() {
  console.log('Offer one-time special');
}).off('event', this, forgetThis);


Methods

has (name) : Boolean public

Module: @ember/object

Defined in packages/ember-runtime/lib/mixins/evented.js:145

name
String

The name of the event

returns
Boolean

does the object have a subscription for event

Checks to see if object has any subscriptions for named event.

off (name, target, method) : public

Module: @ember/object

Defined in packages/ember-runtime/lib/mixins/evented.js:130

name
String

The name of the event

target
Object

The target of the subscription

method
Function

The function of the subscription

returns

this

Cancels subscription for given name, target, and method.

on (name, target, method) : public

Module: @ember/object

Defined in packages/ember-runtime/lib/mixins/evented.js:55

name
String

The name of the event

target
Object

The "this" binding for the callback

method
Function

The callback to execute

returns

this

Subscribes to a named event with given function.

person.on('didLoad', function() {
  // fired once the person has loaded
});

An optional target can be passed in as the 2nd argument that will be set as the "this" for the callback. This is a good way to give your function access to the object triggering the event. When the target parameter is used the callback becomes the third argument.

one (name, target, method) : public

Module: @ember/object

Defined in packages/ember-runtime/lib/mixins/evented.js:81

name
String

The name of the event

target
Object

The "this" binding for the callback

method
Function

The callback to execute

returns

this

Subscribes a function to a named event and then cancels the subscription after the first time the event is triggered. It is good to use one when you only care about the first time an event has taken place.

This function takes an optional 2nd argument that will become the "this" value for the callback. If this argument is passed then the 3rd argument becomes the function.

trigger (name, args) public

Module: @ember/object

Defined in packages/ember-runtime/lib/mixins/evented.js:107

name
String

The name of the event

args
Object...

Optional arguments to pass on

Triggers a named event for the object. Any additional arguments will be passed as parameters to the functions that are subscribed to the event.

person.on('didEat', function(food) {
  console.log('person ate some ' + food);
});

person.trigger('didEat', 'broccoli');

// outputs: person ate some broccoli
On this page


Methods

  • has
  • off
  • on
  • one
  • trigger
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2025 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue Created with Sketch.