insertAngularView method

Future<ImperativeViewRef> insertAngularView(
  1. HtmlElement intoDomElement,
  2. TemplateRef templateRef,
  3. ViewContainerRef viewContainer
)

Returns a future that completes after inserting templateRef into template location, preserving existingLocation's scope if supplied.

The returned instance can be destroyed by disposing it.

WARNING: This code is experimental.

Implementation

Future<ImperativeViewRef> insertAngularView(HtmlElement intoDomElement,
    TemplateRef templateRef, ViewContainerRef viewContainer) {
  return _domService.onWrite().then((_) {
    var viewRef = viewContainer.createEmbeddedView(templateRef);
    for (final rootNode in viewRef.rootNodes) {
      intoDomElement.append(rootNode);
    }
    return ImperativeViewRef._(viewRef, () {
      var index = viewContainer.indexOf(viewRef);
      if (index > -1) viewContainer.remove(index);
    });
  });
}