Guest User

Untitled

a guest
Jun 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. // first we need an componentInjector to initialize the component.
  2. // here the injector is from outside of Custom Element, user can register some of their own
  3. // providers in it.
  4. const componentInjector = Injector.create({providers: [], parent: injector});
  5. // analyze projectable nodes from element
  6. // for example:
  7. // <app-hello>
  8. // <div class="inside">some projection content</div>
  9. // </app-hello>
  10. const projectableNodes = injector.get(ComponentFactoryResolver).resolveComponentFactory(component);
  11. // Here we got all we need, we will initialize the component
  12. const componentRef = componentFactory.create(componentInjector, projectableNodes, element);
  13.  
  14. // Then we need to check whether we need to initialize value of component's input
  15. // the case is, before Angular Element is loaded, user may already set element's property.
  16. // those values will be kept in an initialInputValues map.
  17. componentFactory.inputs.forEach(prop => componentRef[prop] = initialInputValues.get(prop));
  18.  
  19. // and we will also stream Component's @Output -> Element's EventEmitter
  20. initializeOutputs();
  21.  
  22. // then we will trigger a change detection so the component will be rendered in next tick.
  23. changeDetectorRef.detectChanges();
  24.  
  25. // finally we will attach this component's HostView to applicationRef
  26. applicationRef.attachView(this.componentRef.hostView);
Add Comment
Please, Sign In to add comment