An ember-cli addon to manage modals as promises.
In your application's directory:
ember install ember-modal-service
// Inject the service
modal: Ember.inject.service(),
...
// To open a modal use the method `open` with the modal name and the options for the modal.
this.get('modal').open('foo', { bar: 'bar' });
// The returning value of the modal is a promise that is resolved or rejected when the modal is closed.
this.get('modal').open('foo').then(() => {
// modal closed
});
// In order to register a new modal, you need to register the modal object in the application container.
// app/components/modal-foo.js
import ModalComponent from 'ember-modal-service/components/modal';
export default ModalComponent.extend();
All the modals are shown in the modal container.
{{! templates/application.hbs }}
{{modal-container}}
You can close all modals by using the close
method.
this.get('modal').close();
Or just some of them.
this.get('modal').close((modal) => {
return modal.name === 'foo';
});
this.get('modal').close('name', 'foo');
Base modal component provides resolve
& reject
actions so you can implement basic closing behaviour directly on the template. You can pass any arguments you want the modal to be resolved / rejected with
<button {{action "reject" "foo" "bar"}}>Close modal</button>
If you want to contribute to this addon, please read the CONTRIBUTING.md.