1

So I have an object like this:

class FileData {
    file: File;
    description: string;
}

In my components.ts I have an array of this object that contains an unknown amount. My component.html looks like this:

<tr *ngFor="let file of fileArray">
    <td>
        <input type="text" class="form-control" [(value)]="file.description" placeholder="Description">
    </td>
    <td>
        <input type="text" class="form-control" [(value)]="file.file.name" placeholder="File name">
    </td>
</tr>

My goal was that I can change the values of each property within the array with two way binding but this doesn't work.

Whats the right way to do this?

(Usecase: The Array contains X Elements. each one hase a file but no desciption. I want to fill the description or Change the file name)

1
  • I think you look for ngModel Commented Feb 6, 2020 at 8:30

1 Answer 1

1

You need to use ngModel instead of value to bind values from an input:

[(ngModel)]="file.description"
[(ngModel)]="file.file.name"
Sign up to request clarification or add additional context in comments.

3 Comments

Now it says Can't bind to 'ngModel' since it isn't a known property of 'input'. Do I need to import something?
you need to import FormsModule 🤔🤔
Ah of course, you have to enable the FormsModule. Into the imports add FormsModule.

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.