Angular creating array on model change not working

arrays angular typescript

36 观看

2回复

185 作者的声誉

I have quantity:number variable and quantityArray: number[] array. In my template i have two buttons and one input field. when i click the buttons or when i change input field quantity must increment or decrement. and quantityArray must change its length according to quantity. When i click buttons everything works fine. But when i change the input field quantity changes but length of quantityArray is not changing

here's link

作者: N1gthm4r3 的来源 发布者: 2017 年 9 月 15 日

回应 2


1

371003 作者的声誉

决定

Ensure the value is treated as number

 return new Array<number>(Number(qty));

Plunker example

作者: Günter Zöchbauer 发布者: 2017 年 9 月 15 日

0

16800 作者的声誉

Change input type to "number". It's text for now.

<input type="number" [ngModel]="quantity" (ngModelChange)="qtyChange($event)">
作者: Vega 发布者: 2017 年 9 月 15 日
32x32