question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support transform DOM to ViewContainerRef

See original GitHub issue

Feature Request

Relevant Package

This feature request is for @angular/core

Description

Provider a API to transform DOM to ViewContainerRef, What I want have being posted in stack overflow.

Describe the solution you’d like

const dom = document.querySelect('.ref');
const vcr: ViewContainerRef = xxxx.toVcr(dom);

Describe alternatives you’ve considered

Have you considered any alternative solutions or workarounds?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:34
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Eve-Samacommented, Jul 3, 2021

I have a new resolution with CDK. It can help me insert a component to a preset dom.

  protected renderAngularContent() {
    this.unmountAngularContent();
    const root = this.getContentContainer();
    if (root) {
      const node = this.cell;
      const { injector, content } = this.graph.hook.getAngularContent(node);
      const applicationRef = injector.get(ApplicationRef);
      const viewContainerRef = injector.get(ViewContainerRef);
      const componentFactoryResolver = injector.get(ComponentFactoryResolver);
      const domOutlet = new DomPortalOutlet(root, componentFactoryResolver, applicationRef, injector);
      if (content instanceof TemplateRef) {
        const portal = new TemplatePortal(content, viewContainerRef);
        domOutlet.attachTemplatePortal(portal);
      } else {
        const portal = new ComponentPortal(content as any, viewContainerRef);
        domOutlet.attachComponentPortal(portal);
      }
    }
  }
0reactions
angular-automatic-lock-bot[bot]commented, Sep 13, 2021

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exploring Angular DOM manipulation techniques using ...
The article explores common elements used for DOM manipulation in Angular with a particular focus on ViewContainerRef. Learn why they are needed, ...
Read more >
ViewContainerRef - Angular
Property, Description. abstract element: ElementRef, Read-Only. Anchor element that specifies the location of this container in the containing view.
Read more >
How to extract ViewContainerRef and ComponentRef in most ...
I work with angular-material mdSidenav and want to programmatically open it and insert custom component. I use @ViewChild('varName') to extract ...
Read more >
Angular ElementRef, TemplateRef, and ViewContainerRef ...
An overview of ElementRef, TemplateRef, ViewRef, and ViewContainerRef in Angular and how to modify the DOM programmatically. Read to learn more.
Read more >
Angular: View Container and Renderer | by Sabya Sachi
Renderer: Use when we need to change/read DOM element properties. ViewContainerRef: Use when we need to modify DOM hierarchy. We will try to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found