如何使用0初始化参数

时间:2018-05-23 15:33:12

标签: javascript angular typescript

我有这个简单的输入

 // I loop this input  many times so it generates a lot of inputs with different index
 <input value='0' type='number' [(ngModel)]="clients.clientInputs[idx]"/>

这个简单的课程

export class Clients {
  clientInputs = [];
}

在我的ts文件中

  clients:Clients = new Clients();

问题是它们使用null覆盖默认值0。如何使用0初始化该数组中的所有内容?

这个问题来自我上一个问题的答案:Very Simple usage of ngModel

2 个答案:

答案 0 :(得分:2)

您可以使用Array.fill()来填充&#39;数组的所有元素。

示例:

Array(5).fill(0) // output: [0,0,0,0,0]

答案 1 :(得分:0)

如果我了解你拥有的内容,每个客户端类型都有一个输入,这样你就可以为客户端类型做一个循环,并将数组中的每个客户端类型输入初始化为0,如下所示:

 var newProcessInfo = new System.Diagnostics.ProcessStartInfo();
 newProcessInfo.FileName = @"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe";
 newProcessInfo.Verb = "runas";
 newProcessInfo.Arguments = string.Format("pnputil -i -a \"{0}\"", driverPath);
 System.Diagnostics.Process.Start(newProcessInfo);