我有两个接口,Test和TestTwo;我有一个func getTest()函数,它返回一个空的Test []数组; 我在onInit的testArr上使用它,所以现在它是一个Test类型的空数组; 我需要获取属于TestTwo []类型的属性文本,然后单击并写入一个值。我需要精确地在prop子文本中写值:string [];然后将其显示为html
.ts
export class AppComponent implements OnInit {
title = 'arry';
testArr: Test[] = [];
ngOnInit(){
this.testArr = this.getTest();
}
addRes() {
console.log(this.testArr);
for (const iterator of this.testArr) {
iterator.text = [{subtext: ['a', ...subtext]}];
}
}
getTest(): Test[]{
let some: TestTwo[] = [];
return [{
text: some
}];
}
}
export interface Test {
text: TestTwo[];
}
export interface TestTwo{
subtext: string[];
}
.html
<div
*ngFor="let item of testArr; index as i"
>
<button (click)="addRes()">add</button>
<div *ngFor="let items of item.text; index as i">
{{items.subtext}}
</div>
</div>
因此,我需要在按钮点击时动态添加“ a”,并复制我以前的值;