Skip to content

Instantly share code, notes, and snippets.

@robwormald
Last active Jun 26, 2018
Embed
What would you like to do?
import {ɵrenderTemplate as renderTemplate} from '@angular/core'
export function withNgTemplate(Base = HTMLElement){
return class NgTemplateElement extends HTMLElement {
_renderRoot: HTMLElement | ShadowRoot;
_host:any;
_renderer(root:HTMLElement | ShadowRoot, renderFn:any){
renderFn();
}
_render(){
this._host = renderTemplate(this._renderRoot as HTMLElement, (this.constructor as any).ngTemplate, this, {
createRenderer(){ return document; }
}, this._host, null, null, null );
}
detectChanges(){
this._renderer(this._renderRoot, () => this._render && this._render());
}
}
}
import {withNgTemplate} from '@angular/core'
//@Template({})
class MyElement extends withNgTemplate(){
}
customElements.define('x-foo', MyElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment