javascript 如何在Angular 中更新同一组件中的输入值

f87krz0w  于 2022-11-27  发布在  Java
关注(0)|答案(1)|浏览(107)

尝试更新同一组件中的输入值,但无法更新。出现如下错误

ERROR
Error: Cannot read properties of undefined (reading 'pop')

那么,如何解决这个问题呢?
table.component.ts:

export class TableComponent implements OnInit {
@Input() names: any;

constructor() {}

ngOnInit() {}

testFn() {
  this.names.pop('Test22');
  this.names = [...this.names];
  console.log(this.names);
}

}

演示:https://stackblitz.com/edit/angular-pass-table-data-to-input-property-dlsufy?file=src%2Fapp%2Ftable%2Ftable.component.ts

相关问题