Javascript 在IONIC2中获取动态创建的ion输入值

Javascript 在IONIC2中获取动态创建的ion输入值,javascript,angular,typescript,ionic2,ionic3,Javascript,Angular,Typescript,Ionic2,Ionic3,我有以下HTML部分,其中基于*ngFor <ion-list *ngIf="Label_view"> <ion-item style="Float:Right;margin-left: 4%;" *ngFor="let bil of arr_label;let i=index "> <ion-label floating>{{bil}}</ion-label> <ion-input [(ngModel)]="array

我有以下HTML部分,其中基于
*ngFor

<ion-list *ngIf="Label_view">

  <ion-item style="Float:Right;margin-left: 4%;" *ngFor="let bil of arr_label;let i=index ">
    <ion-label floating>{{bil}}</ion-label>
    <ion-input [(ngModel)]="array" id={{i}}  type="text"  maxlength="5"></ion-input>
  </ion-item>
我没有定义控制台输出。
是否缺少某些内容?

问题是因为您试图将数组与输入元素绑定。它应该绑定到字符串或数字(或数组的单个位置

而不是像这样做:

  <ion-item style="Float:Right;margin-left: 4%;" *ngFor="let bil of arr_label;let i=index ">
    <ion-label floating>{{bil}}</ion-label>
    <ion-input [(ngModel)]="array" id={{i}}  type="text"  maxlength="5"></ion-input>
  </ion-item>
this.newArray : Array<{id: number, value: string}> = [];

// Assuming the `arr_label` exists and it has been properly initialized
for(let i=0; i < arr_label.length; i++) {
    this.newArray.push({ id: i, value: arr_label[i] });
}
在你看来:

  // We only iterate over the newArray because all the information we need is there
  <ion-item style="Float:Right;margin-left: 4%;" *ngFor="let bill of newArray">

    <ion-label floating>{{bill.value}}</ion-label>
    <ion-input [(ngModel)]="array[bill.id]" type="text" maxlength="5"></ion-input>

  </ion-item>
//我们只迭代newArray,因为我们需要的所有信息都在那里
{{bill.value}}
注意,我们现在使用
id
(即0、1等)将
输入绑定到数组的单个位置


你可以找到一份工作。请看一下
Page1.ts
Page1.html

中的代码,因为您将数组作为一个模型放置,所以未定义。它应该是字符串或数字。比如[(ngModel)]=“bil.Id”谢谢..:)@misha130
  // We only iterate over the newArray because all the information we need is there
  <ion-item style="Float:Right;margin-left: 4%;" *ngFor="let bill of newArray">

    <ion-label floating>{{bill.value}}</ion-label>
    <ion-input [(ngModel)]="array[bill.id]" type="text" maxlength="5"></ion-input>

  </ion-item>