Giter Site home page Giter Site logo

Comments (2)

pkozlowski-opensource avatar pkozlowski-opensource commented on April 28, 2024

I would need a fast, efficient, and synchronous Angular clone method that clone the HTML element as the cloneNode Javascript method WITH all its Angular elements attached.

A <ng-template> + TemplateRef + ViewContainerRef is the way of achieving this. Those are very much optimized for what they need to do - that is - support all existing Angular functionality.

I don't think we can expect Angular template cloning to be as fast as DOM template cloning - there is just more work to be done.

There are multiple widgets libraries that use the Angular API to deliver widgets with adequate performance but I'm happy to look into specific performance bottlenecks if you can share a minimal reproduce scenario of the <ng-template> + TemplateRef + ViewContainerRef being "slow".

from angular.

GreenFlag31 avatar GreenFlag31 commented on April 28, 2024

Not able to make this work or not possible within my current configuration. I have a ng-content which is used for content projection. Due to the nature of ng-content, it will not be rendered multiple times.

Ts:

@ViewChild('tpl', { read: TemplateRef }) tpl!: TemplateRef<any>;
@ViewChild('vc', { read: ViewContainerRef }) vc!: ViewContainerRef;
...
this.vc.createEmbeddedView(this.tpl);
this.vc.createEmbeddedView(this.tpl);

Template:

<ng-container #vc></ng-container>
<ng-template #tpl>
  <ng-content></ng-content>
</ng-template>

=> this is only rendered once.

Using a select attribute on the ng-content does not solve the problem (doc), the nature of ng-content does not allow duplication of template content.

Please let me at least try and think about potential solutions before anticipatively close the ticket.

from angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.