How can I append a variable after my form template name?

Hi, on my application, I have a loop containing a form, I would like to append a number after each of my forms so they are unique

in my loop I have an index so I am outputting 1/4 as below


In my form I would like to append that number

<form #userForm="ngForm">

So I would like to do something like this:

<form #userForm{{i}}="ngForm">

but this doesn’t work?!

Did you try using [id] instead of #, like [id]="userForm{{i}}"?

hmm, thanks but that didn’t work, It needs to be the local template variable as I’m using reactive forms

Sorry, I didn’t get what you’re trying to accomplish… I think template variables are local, so you don’t really need to have dynamic naming for them. Just #userForm="ngForm" should work. In each iteration of your loop it will referencing the current form

What are you using? I’m confused with all the brackets. Why not { (i+1) +'/'+ totalCount } and <form #userForm{i+1}="ngForm">? I’m still new; I thought double brackets were for objects.

I would like The thing is, I don’t want it to reference the current form in each iteration, I would like it to have a unique form per iteration

it doesn’t seem to like this:

<form #userForm{i+1}="ngForm">

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.