Angular creating array on model change not working

arrays angular typescript

36 观看


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)


371003 作者的声誉


Ensure the value is treated as number

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

Plunker example

作者: Günter Zöchbauer 发布者: 15.09.2017 05:57


16800 作者的声誉

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

<input type="number" [ngModel]="quantity" (ngModelChange)="qtyChange($event)">
作者: Vega 发布者: 15.09.2017 06:09