Skip to content

Instantly share code, notes, and snippets.

@robwormald
Last active June 26, 2018 17:24
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 robwormald/ce0c959c944bff7f0d796ab86f15895d to your computer and use it in GitHub Desktop.
Save robwormald/ce0c959c944bff7f0d796ab86f15895d to your computer and use it in GitHub Desktop.
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