How can I pass arbitrary data for rendering in an Ember template?

So we are trying to render custom content to a template.

We have this template:

<div class="modal-container">
  <div class="popup modal error">
    <header>
      <p>Error!</p>
      <div class="close" {{action 'closeModal'}}>
        <i class="fa fa-close"></i>
      </div>
    </header>
    <div class="content">
      {{message}}
    </div>
  </div>
</div>

      

.. using this app route:

App.ApplicationRoute = Ember.Route.extend
  actions:

    displayError: (message) ->
      @render 'error-modal', 
        into: 'application'
        outlet: 'error-modal'
        model: Ember.Object.create message: message

      

And in our controller, we call:

@send 'displayError', 'Error message.'

      

Modal popups are just fine, but no message is displayed. What are we doing wrong?

+3


source to share


1 answer


You can use a generic controller (template and modal) to set the error message:

displayError: (message) ->
  @controller.set('errorMessage', message)
  @render 'error-modal', 
    into: 'application'
    outlet: 'error-modal'

      



In the template: {{errorMessage}}

.

+1


source







All Articles