3

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!

10
  • What would you need this for? Commented Feb 28, 2016 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. Commented Feb 28, 2016 at 18:14
  • You can pass additional parameters to event handlers. Commented Feb 28, 2016 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 Commented Feb 28, 2016 at 18:17
  • Actually I can imagine use cases, also dynamic forms. Commented Feb 28, 2016 at 18:18

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

You can bind variable to input value like this:

<input name="{{ name }}" ng-model="name">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.