Skip to content

Instantly share code, notes, and snippets.

@zoechi
Last active September 21, 2015 11:06
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 zoechi/cfa606c738e3f36662b3 to your computer and use it in GitHub Desktop.
Save zoechi/cfa606c738e3f36662b3 to your computer and use it in GitHub Desktop.
// not tested with binding expressions (port of http://stackoverflow.com/a/31320384/217408)
// probably needs bound values set to `template`
injectBoundHtml(highlightedValue, $['container']);
// TODO(zoechi) create feature request to get this into the `Polymer` class
get _polymerBase {
final JsObject _polymer = context['Polymer'];
return (o) {
return o is JsObject ? o : new JsObject.fromBrowserObject(o);
}(_polymer['Base']);
}
void injectBoundHtml(String html, HtmlElement element) {
TemplateElement template = document.createElement('template', 'dom-bind');
var doc = template.content.ownerDocument;
DivElement div = doc.createElement('div');
div.setInnerHtml(html, validator: _nodeValidator);
template.content.children.add(div);
element.children.clear();
element.append(_polymerBase.callMethod('instanceTemplate', [template]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment