Skip to content

Instantly share code, notes, and snippets.

@Manuel-S
Last active January 12, 2016 10:02
Show Gist options
  • Select an option

  • Save Manuel-S/ee91164eb2a845737334 to your computer and use it in GitHub Desktop.

Select an option

Save Manuel-S/ee91164eb2a845737334 to your computer and use it in GitHub Desktop.
Aurelia custom element to put a DOM Element from the viewmodel to the view
import {bindable, noView, inject} from 'aurelia-framework';
/* USAGE
<content-control content.bind="domElement"></content-control>
*/
@noView
@inject(Element)
export class ContentControl{
@bindable content;
constructor(el){
this.element = el;
}
contentChanged(newValue){
if(this.element.firstChild)
this.element.removeChild(this.element.firstChild);
if(newValue instanceof Node)
this.element.appendChild(newValue);
}
detached(){
if(this.element.firstChild)
this.element.removeChild(this.element.firstChild);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment