Skip to content

Instantly share code, notes, and snippets.

@iheanyi
Last active January 18, 2016 17:31
Show Gist options
  • Save iheanyi/ba3dc0c691bc2e8c2516 to your computer and use it in GitHub Desktop.
Save iheanyi/ba3dc0c691bc2e8c2516 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Dynamic Components Example',
currentModal: null,
showModal: Ember.computed('currentModal', function() {
return !!this.get('currentModal');
}),
actions: {
openModalA() {
this.set('currentModal', 'modal-a');
},
openModalB() {
this.set('currentModal', 'modal-b');
},
closeModal() {
this.set('currentModal', null);
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{#if showModal}}
{{#x-modal close=(action 'closeModal')}}
{{component currentModal}}
{{/x-modal}}
{{/if}}
<button {{action 'openModalA'}}>Open Modal A</button>
<button {{action 'openModalB'}}>Open Modal B</button>
{{outlet}}
<br>
<br>
import Ember from 'ember';
import ModalComponent from 'demo-app/x-modal/component';
export default ModalComponent.extend({
});
This is Modal A
{{yield}}
import Ember from 'ember';
export default Ember.Component.extend({
});
This is Modal B
{{yield}}
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js",
"tachyons": "https://cdnjs.cloudflare.com/ajax/libs/tachyons/3.0.2/tachyons.min.css"
}
}
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
close() {
this.get('close')();
}
}
});
Parent Component <button {{action 'close'}}>Close Modal</button>
{{yield}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment