home
  • Blog
1.10
  • Getting Started
  • Getting Ember
  • Concepts
  • The Object Model
  • Application
  • Templates
  • Routing
  • Components
  • Controllers
  • Models
  • Views
  • Enumerables
  • Testing
  • Configuring Ember.js
  • Cookbook
    • Introduction
    • Contributing
    • User Interface and Interaction
      • Introduction
      • Adding CSS Classes to Your Components
      • Adding CSS Classes to Your Components Based on Properties
      • Focusing a Textfield after It's Been Inserted
      • Displaying Formatted Dates With Moment.js
      • Specifying Data-Driven Areas of Templates That Do Not Need To Update
      • Using Modal Dialogs
      • Resetting scroll on route changes
    • Event Handling & Data Binding
    • Helpers & Components
    • Working with Objects
  • Understanding Ember.js
  • Contributing to Ember.js
Old Guides - You are viewing the guides for Ember v1.10.0.
Go to v5.0.0

Using Modal Dialogs

Edit pencil

Problem

You want to show part of your UI in a modal dialog.

Solution

Render a specific controller into a named modal outlet in your application template.

Discussion

You can use a route's render method to render a specific controller and template into a named outlet. In this case we can setup our application template to handle the main outlet and a modal outlet:

{{outlet}}
{{outlet 'modal'}}

Then you can render a controller and template into the modal outlet. Sending an action in a template will propagate to the application route's actions.

In a template:

<button {{action 'openModal' 'myModal'}}>Open modal</button>

In your application route:

App.ApplicationRoute = Ember.Route.extend({
  actions: {
    openModal: function(modalName) {
      return this.render(modalName, {
        into: 'application',
        outlet: 'modal'
      });
    }
  }
});

When closing a modal, you can use the route's disconnectOutlet method to remove the modal from the DOM.

  closeModal: function() {
    return this.disconnectOutlet({
      outlet: 'modal',
      parentView: 'application'
    });
  }

It may also be helpful to use a modal-dialog component to handle common markup and interactions such as rendering an overlay and handling clicks outside of the modal.

Example

This example shows:

  1. Rendering a pop-up modal in a named outlet.
  2. Sending a specific model to the modal controller.
  3. Wrapping the common modal markup and actions in a component.
  4. Handling events to close the modal when the overlay is clicked.

Recipe: Using a Modal Dialog

left arrow
Specifying Data-Driven Areas of Templates That Do Not Need To Update
Resetting scroll on route changes
right arrow
On this page

  • Problem
  • Solution
  • Discussion
  • Example
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 2023 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue