0

I have just started with angular2 and the concept / architecture of how they implement templates using *ngFor, *ngIf and defining of my own <template> elements is new to me.

What I would like to know though (because it wasn't broached in the documentation), is that are there any performance hits to defining huge quantities of templates?

For example;

<div *ngFor="let screen of screens" [ngSwitch]="screen.templateID"> <!-- huge loop -->
  <template [ngSwitchCase]="0">{{screen.id}} | {{screen.templateURL}}</template>
  <template [ngSwitchCase]="1">{{screen.id}} | {{screen.templateURL}}</template>
  <template [ngSwitchCase]="1">{{screen.id}} | {{screen.templateURL}}</template>
</div>

Which could hypothetically generate thousands of templates, is it "acceptable" to generate so many templates or should I add more logic in to reduce the amount being instantiated?

Zze
  • 18,229
  • 13
  • 85
  • 118
  • I guess you'll need to do your own benchmarks. I don't see any obvious reason why it would be a problem. ` – Günter Zöchbauer Feb 14 '17 at 06:49
  • Interesting, thanks @GünterZöchbauer - I ended up using routes in the end which completely mitigated this issue. Whilst I have your attention, can you please look at my other [question](http://stackoverflow.com/questions/42218239/viewchild-is-undefined) on Angular2, when i was researching this issue, your attribution to the github issue on this topic was very insightful and so fingers crossed, you will easily see what is causing my drama. Thanks for your time. – Zze Feb 14 '17 at 09:23

0 Answers0