Angular的MatTable不会使用来自表单的数据进行更新。
创始人
2024-10-24 07:01:20
0

在提交表单时,手动更新MatTable的数据源。可以使用以下代码:

在组件中声明一个数组来保存数据:

export class ExampleComponent implements OnInit {

dataSource: MatTableDataSource; exampleData: ExampleItem[] = [];

// ... 省略其他代码 ...

}

在表单提交时更新数据源:

onSubmit() { // get form data const formData = this.exampleForm.value;

// create new item const newItem = { // map form data to item properties name: formData.name, age: formData.age, // ... 省略其他属性 ... };

// push new item to data array this.exampleData.push(newItem);

// create new MatTable data source with updated data this.dataSource = new MatTableDataSource(this.exampleData);

// update table sorting and pagination // if necessary, for example: this.dataSource.sort = this.sort; this.dataSource.paginator = this.paginator;

// clear form this.exampleForm.reset(); }

在HTML模板中设置MatTable:

Name {{ row.name }}

Age {{ row.age }}

相关内容

热门资讯

透视黑科技!aapoker怎么... 透视黑科技!aapoker怎么设置抽水(透视)免费透视脚本(一直是真的有挂)1、进入游戏-大厅左侧-...
透视黑科技!aapoker俱乐... 透视黑科技!aapoker俱乐部靠谱吗(透视)ai插件(一直是有挂);进入游戏-大厅左侧-新手福利-...
透视免费!aapoker脚本怎... 透视免费!aapoker脚本怎么用(透视)透视方法(原来是有挂);1.aapoker脚本怎么用 ai...
透视软件!aapoker安装包... 透视软件!aapoker安装包怎么使用(透视)真的假的(一直是有挂);1、aapoker安装包怎么使...
透视ai代打!aapoker ... 透视ai代打!aapoker ai插件(透视)辅助插件工具(真是真的有挂)1、aapoker ai插...
透视玄学!aapoker发牌逻... 透视玄学!aapoker发牌逻辑(透视)透视脚本下载(一贯是有挂)1、很好的工具软件,可以解锁游戏的...
透视有挂!aapoker发牌逻... 透视有挂!aapoker发牌逻辑(透视)辅助插件工具(真是是真的有挂)1、下载好aapoker发牌逻...
透视总结!aapoker怎么控... 透视总结!aapoker怎么控制牌(透视)万能辅助器(一直真的有挂);透视总结!aapoker怎么控...
透视实锤!aapoker透视脚... 透视实锤!aapoker透视脚本下载(透视)脚本(确实是有挂);一、aapoker透视脚本下载AI软...
透视辅助!aapoker俱乐部... 透视辅助!aapoker俱乐部靠谱吗(透视)辅助(总是真的是有挂)1、透视辅助!aapoker俱乐部...