0

I am facing issue in binding the response values to input type text in a ngFor loop.

<div *ngFor = "let item of items">
     <input type="text"  class="form-control" #inputTarget>
  <div>

if I bind, all the text box binding same values. how should bind different item values to each text box

1
  • (1) Are the items string variables? (2) Are these controls inside of a form tag? Commented Apr 12, 2018 at 14:07

2 Answers 2

1

You should use attribute binding, [value]="item"

<div *ngFor = "let item of items">
     <input type="text"  class="form-control" #inputTarget [value]="item">
<div>

The above code takes the item and assigns to value of the text box

Here is a small DEMO for the same

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

Comments

0

Set the [value] item

<div *ngFor = "let item of items">
     <input type="text"  [value]="item" class="form-control" #inputTarget>
<div>

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.