Skip to content

Instantly share code, notes, and snippets.

@brakmic
Last active March 12, 2017 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brakmic/49ee02aa5547239c1063c247cec6b158 to your computer and use it in GitHub Desktop.
Save brakmic/49ee02aa5547239c1063c247cec6b158 to your computer and use it in GitHub Desktop.
dynamic creation of Angular components
const body = document.getElementsByTagName('body')[0];
// if the markup has changed remove the existing vr-module scripts first
Promise.resolve(_.each(this.activeScripts, (script, index) => {
const oldNode = body.removeChild(document.getElementById(this.vrScriptPrefix + index));
})).then(() => {
// clean up the view-container reference...
this.activeScripts = [];
_.each(cmp.scripts, (script, idx) => {
this.appendScript(body, script, Number(idx))
});
});
const metadata = new Component({
selector: 'vr-dynamic-element',
template: cmp.html,
});
createComponentFactory(this.compiler, metadata).then((factory) => {
const injector = ReflectiveInjector.fromResolvedProviders([],
this.vcRef.parentInjector);
this.cmpRef = this.vcRef.createComponent(factory, 0, injector, []);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment