ThorstenHans / ama

Ask me Anything - Keep questions and answers organized
https://www.xplatform.rocks
0 stars 0 forks source link

Question on Local template variables #2

Open sverma16 opened 7 years ago

sverma16 commented 7 years ago

Thorton

Thanks for a very informative article. Can these variables be created dynamically? ie depending on the number of records can i create #firstname_0, #firstname_1 using a *ngFor index?

SV

ThorstenHans commented 7 years ago

which article do you mean?

sorry for the delay :D had to configure my github notifications, now I get instant feedback 👍

ThorstenHans commented 7 years ago

having *ngFor you got automatically associated the current item to the variable you define within the expression.

like

<div *ngFor="let item of items; let i = index">
   <span>Index: {{i}} title: {{item.title}}</span>
</div>
sverma16 commented 7 years ago

Sorry to miss the link. Here is the article https://www.xplatform.rocks/2016/01/07/angular2-quicky-local-template-variables/

I understand that these variables cannot and should not be created dynamically.

ThorstenHans commented 7 years ago

Ah I see,

what's the use case? What do you want to achieve by storing those values as dedicated variables?

If you could describe the use case a bit more, I can give you a better advice.

😄