Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays NGF用于在开始时显示第一个元素-角度2_Arrays_Angular_Row_Ngfor - Fatal编程技术网

Arrays NGF用于在开始时显示第一个元素-角度2

Arrays NGF用于在开始时显示第一个元素-角度2,arrays,angular,row,ngfor,Arrays,Angular,Row,Ngfor,每次单击“添加行”按钮时,我都会生成一行输入和下拉列表。使用其他按钮,我提交完整的数据,您可以在console.log中看到它。作为对象数组,其中每个对象实际上就是该行 现在看起来是这样的: ngOnInit() { this.properties[0] = this.property; } 但我需要它看起来像这样: ngOnInit() { this.properties[0] = this.property; } 我在弹出窗口中使用它,当弹出窗口打开时,我需要立即显示第一行,

每次单击“添加行”按钮时,我都会生成一行输入和下拉列表。使用其他按钮,我提交完整的数据,您可以在console.log中看到它。作为对象数组,其中每个对象实际上就是该行

现在看起来是这样的:

ngOnInit() {
  this.properties[0] = this.property;
}

但我需要它看起来像这样:

ngOnInit() {
  this.properties[0] = this.property;
}

我在弹出窗口中使用它,当弹出窗口打开时,我需要立即显示第一行,在我点击“添加行”按钮后,每隔一行应该生成一行。 最后,当我提交all时,第一行应该首先放在数组中,然后是生成的其余行

有没有办法用索引来改变这一点,或者有其他解决方案

数组如下所示:

 0: {name: "A", data: "123", num: "number1", char: "letter1"}
  1: {name: "B", data: "234", num: "number2", char: "letter2"}
  2: {name: "C", data: "345", num: "number3", char: "letter3"}

您需要实现ngOnInit并将属性[0]添加为空属性,如下所示:

ngOnInit() {
  this.properties[0] = this.property;
}

这方面的例子。

嘿,我记得你的砰砰声!我相信是我纠正了它。你应该问你的另一个问题

若要强制将选定项上的值作为默认值,请为绑定到选定项的模型指定一个值。例如,创建新行时,将模型的值设置为所选内容的第一个选项

createRow(){
  this.properties.push({ 
    name:"",
    data: "",
    num: this.numberTypes[0],
    char: this.charTypes[0]
  });
}

嘿,伙计,很高兴见到你…完全忘了我可以在同一主题上发布其他问题。。。卡西亚诺刚刚给了我答案,但你们只是解决了我一直在寻找的另一个问题。多谢!!!