Last active
August 21, 2016 18:45
-
-
Save oriSomething/1a4793156675d03072bb42f56d6c9a86 to your computer and use it in GitHub Desktop.
Inject Ember.Component dynamicly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import $ from 'jquery'; | |
const { getOwner, computed } = Ember; | |
export default Ember.Component.extend({ | |
init() { | |
this._super(...arguments); | |
$.getScript('some-dynamic-component-to-inject.js') | |
.then(() => { | |
const component = window.newComponent(Ember); | |
const container = getOwner(this); | |
container.register('component:dynamic-injeted', component); | |
Ember.run(() => { | |
this.set('componentName', 'dynamic-injeted'); | |
}); | |
}); | |
}, | |
componentAttributes: computed(() => Object.create({})), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Needs to be compiled with 'htmlbars-inline-precompile' | |
window.newComponent = function(Ember) { | |
return Ember.Component.extend({ | |
layout: hbs`<h1>hi {{ args.name }}</h1>` | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment