Skip to content

Instantly share code, notes, and snippets.

@oriSomething
Last active August 21, 2016 18:45
Show Gist options
  • Save oriSomething/1a4793156675d03072bb42f56d6c9a86 to your computer and use it in GitHub Desktop.
Save oriSomething/1a4793156675d03072bb42f56d6c9a86 to your computer and use it in GitHub Desktop.
Inject Ember.Component dynamicly
{{component componentName args=componentAttributes}}
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({})),
});
// 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