Last active
March 12, 2017 13:26
-
-
Save brakmic/49ee02aa5547239c1063c247cec6b158 to your computer and use it in GitHub Desktop.
dynamic creation of Angular components
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
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