Skip to content

Instantly share code, notes, and snippets.

@shama
Created April 17, 2014 22:33
Show Gist options
  • Save shama/11015260 to your computer and use it in GitHub Desktop.
Save shama/11015260 to your computer and use it in GitHub Desktop.

Method for triggering an action on any controller from a component, such as with nested Ember components.

WARNING: You really shouldn't do this as it couples your component to your app, which kind of defeats the purpose of the component, right?

GlobalAction = Ember.Mixin.create
  triggerGlobalAction: (action, controller="application", args...) ->
    @triggerAction
      action: action
      target: @container.lookup('controller:' + controller)
      actionContext: args

MyBadComponent = Ember.Component.extend(GlobalAction, {
  click: (e) ->
    e.preventDefault()
    @triggerGlobalAction('openModal', 'application', 'modals/modal-name')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment