Angular 排序数组后使用setValue形成控件时出错
我有一个错误: 错误:必须在索引1处为窗体控件提供值 我正在用Angular 9做一个应用程序,问题出在Typescript上 以下代码正在运行:Angular 排序数组后使用setValue形成控件时出错,angular,typescript,formarray,Angular,Typescript,Formarray,我有一个错误: 错误:必须在索引1处为窗体控件提供值 我正在用Angular 9做一个应用程序,问题出在Typescript上 以下代码正在运行: this.registros.controls.arrayProcedimientos.setValue(convert.arrayProcedimientos) 但如果我对数组排序,然后执行一个setValue,我不知道会发生什么,但不起作用,例如: convert.arrayProcedimientos.sort(function(a,b){
this.registros.controls.arrayProcedimientos.setValue(convert.arrayProcedimientos)代码>
但如果我对数组排序,然后执行一个setValue,我不知道会发生什么,但不起作用,例如:
convert.arrayProcedimientos.sort(function(a,b){
return a.fechaInicioProcedimiento > b.fechaInicioProcedimiento;
});
//setValue of the sorted array
this.registros.controls.arrayProcedimientos.setValue(convert.arrayProcedimientos);
psd:我尝试了一个patchValue(),它不会抛出错误,但问题是该对象是一个数组数组。因此,在独特的字段上使用patchValue效果很好,但在子数组上则是拖拉(字面意思)
感谢您的关注和帮助,如果您需要一些图片或任何东西,请随时询问
伟大的社区:)我认为首先你需要修正你的分类方式,不确定它对你有什么作用。它必须在排序时给您提供编译时错误
而不是这个
convert.arrayProcedimientos.sort(function(a,b){
return a.fechaInicioProcedimiento > b.fechaInicioProcedimiento;
});
用这个
convert.arrayProcedimientos.sort(function(a,b){
return a.fechaInicioProcedimiento - b.fechaInicioProcedimiento;
});
然后
this.registros.controls.arrayProcedimientos.setValue(convert.arrayProcedimientos);
应该有用
这就是我要求您更改排序语法的原因
非常感谢您的回复。这不完全是答案。我发现了我的问题。问题是我“在值之前准备内存”,所以这就是我检索错误的原因。无论如何,谢谢你抽出时间。