In a component template in angular2, it is possible to add a data-binding variable to an input element:

<input name="title" #title>

Also, we can dynamically set the property value like this:

<input name="{{ name }}" #title>

However, how can we dynamically set these data-binding variables? For example, is it possible to do something like this?

<input name="{{ name }}" #{{ name }}>

Thanks in advance!

share|improve this question
    
What would you need this for? – Günter Zöchbauer Feb 28 '16 at 18:11
    
@GünterZöchbauer I am trying to dynamically create a form and would like to assign variable names dynamically. So that I only have to change the number of variables in my event handler on submit button. I can probably also explore variable length arguments to the event handler function if angular supports it. – Surender Thakran Feb 28 '16 at 18:14
    
You can pass additional parameters to event handlers. – Günter Zöchbauer Feb 28 '16 at 18:16
    
@GünterZöchbauer I am completely new to angular (Only started reading it some 3 hours ago) so apologies if I am suggesting too far fetched usecase. I am basically playing with angular :p – Surender Thakran Feb 28 '16 at 18:17
    
Actually I can imagine use cases, also dynamic forms. – Günter Zöchbauer Feb 28 '16 at 18:18

You can bind variable to input value like this:

<input name="{{ name }}" ng-model="name">
share|improve this answer

No, template variables can't even be set to arbitrary values and also having the name variable isn't supported.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.