[英]Angular change property value of object array in html
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.在我的 components.ts 中,我有一个包含未知数量的对象数组。 My component.html looks like this:我的 component.html 看起来像这样:
<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) (用例:数组包含 X 个元素。每个元素都有一个文件但没有描述。我想填写描述或更改文件名)
You need to use ngModel instead of value to bind values from an input:您需要使用 ngModel 而不是 value 来绑定来自输入的值:
[(ngModel)]="file.description"
[(ngModel)]="file.file.name"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.