How to put ngFor value in input element

            <ion-item *ngFor = "let match of matches">

Hi i want to put the  {{match}} value in input element is it possible?

Thanks for the suggestion but, i’m getting empty input box the value of {{match}} is not reflecting to that input.

<div *ngFor = "let match of matches"></div>
<input #matchInput>{{matchInput.value}}

do console.log(this.matches) and display output here.

value is coming in console.log but not not coming in input box

Here’s an example. At surface level this is a very easy problem to solve, it’s basic Angular.

However if you have an array of just strings or numbers (I have no idea what your array is of since that isn’t posted), it can get a little tricky.

But at it’s basic level it’s just simple Angular binding.

However if your array is of a primitive type, it gets a little tricky because you need a trackBy function. It will still work without it, but your inputs will lose focus.

<div *ngFor="let test of tests; let i = index; trackBy: trackByFn">
  <input [(ngModel)]="tests[i]"/>
export class AppComponent {
  tests = ['a', 'b', 'c'];

  trackByFn(index: any, item: any) {
   return index;

Edit: This assumes you actually want two way binding, which I mean I assume you do but…you don’t specify that in your question.


Thanks for the support.Actually i’m getting the value in input by using ngModel but when i try to change the value which is reflected in my input box i’m getting below error
NgFor only supports binding to iterable such as Arrays

Did you read my example? Did you go out to the actual running example on stackblitz that I made for you? Have you posted the updated code where “you are getting the input value by using ngModel”? Did you bother actually posting what matches is? :weary:

just now i updated the codepls check once

I have no idea what you are talking about. What did you update?

pls check the stack blitz once then you will understand

Maybe you should check it. Because I don’t think you know how it works.

Why won’t you respond to the two very clear and explicit requests for how matches is declared and populated? It seems a virtual certainty that therein lies the bug.

issue cleared thank you

please how did u solve your problem, cause i’m working with the same issue , i need to memorize the value of matches from the speech recognition and send it by a http client sever?

How did you clear the issue please?