0

I generate input fields in the template like this

 <input *ngFor="#number of numbers"  placeholder="Number"/> 

in the component class

export class AppComp{
    public numbers : Array<number> = new Array(10);
}

I need to bind the dynamically added input values to the numbers array. I also need the place holder to read Number 1, Number 2 ... Number 10

2
  • The placeholder only shows when you don't have a value, so if you bind the values of each number in the array on each input you will not see the placeholder text. Do you mean you want to bind the values to a different array other than numbers? Commented Jan 20, 2016 at 18:20
  • Lets say, I have 3 input fields and an array of length 3, I wan to bind each input field values to corresponding array element Commented Jan 20, 2016 at 19:10

1 Answer 1

2

I found the answer from this link https://coryrylan.com/blog/angular-2-ng-for-syntax

 <input *ngFor="#number of numbers; #i = index" [(ngModel)]="numbers[i]"  placeholder="Number {{i}}" " />
Sign up to request clarification or add additional context in comments.

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.