# How to get input value inside ngFor?

**URL:** <https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946>\
**Category:** ionic-v3\
**Created:** [June 14, 2018, 6:01pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946 "2018-06-14T18:01:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sigautomacao](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sigautomacao](https://forum.ionicframework.com/u/sigautomacao)\
**Post date:** [June 14, 2018, 6:01pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946/1 "2018-06-14T18:01:24Z")

</div>

I need to get input value inside ngFor, are inputs created dynamically with ngFor and wanted the value of each.

```auto
<ion-item-group *ngIf="adicionais && adicionais.length">
 <ion-item-divider color="light">Adicionais</ion-item-divider>
	<ion-item *ngFor="let adc of adicionais;let i = index">
	<ion-label>{{adc.descri}} - R$ {{money(adc.preco)}}:</ion-label>
	    	<ion-input type="text" value="0" [(ngModel)]="adcs[i].qtd" (keyup)="addc()"></ion-input>
	</ion-item>
</ion-item-group>

```

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [June 14, 2018, 7:18pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946/2 "2018-06-14T19:18:45Z")

</div>

Look in the `qtd` property of each member of `adcs`.

---

<div class="post-metadata">

**Author:** ![sigautomacao](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sigautomacao](https://forum.ionicframework.com/u/sigautomacao)\
**Post date:** [June 14, 2018, 7:24pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946/3 "2018-06-14T19:24:27Z")

</div>

```auto
<ion-input type="text" (keyup)="valChange($event.target.value, adc.idADC)"></ion-input>

```

I did it another way. now I need to enter data inside an array how do I?

```auto
let dados:any[] = [{'idADC':idADC, 'qtd':value}];
      this.adcs.push(dados);

```

it is showing an error: “ERROR TypeError: Cannot read property ‘push’ of undefined”;

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [June 14, 2018, 7:26pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946/4 "2018-06-14T19:26:27Z")

</div>

You’ve made it worse. Can we go back to ordinary life with a normal `[(ngModel)]` binding and no `keyup` listener? Let the framework handle low-level events: that’s what it’s good at.

---

<div class="post-metadata">

**Author:** ![sigautomacao](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sigautomacao](https://forum.ionicframework.com/u/sigautomacao)\
**Post date:** [June 14, 2018, 7:29pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946/5 "2018-06-14T19:29:56Z")

</div>

ok, so let’s go: my variable that gets ngModel is this:

```auto
adcs:any[];

```

I need two information in it for input with value above 0: Quantity and ID. How do I do ?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [June 14, 2018, 7:51pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946/6 "2018-06-14T19:51:07Z")

</div>

Don’t abuse `any` and the build tools will help you find your bug.

Declare an actual interface, such as

```auto
interface Adicional {
  id: string;
  qtd: string;
}

```

…now `adcs` will be of type `Adicional[]`, and should be initialized at the point of declaration:

```auto
adcs: Adicional[] = [];

```

Now your “Cannot read property ‘push’ of undefined” should be fixed, because `adcs` is no longer undefined when you try to call its `push` method. Additionally, one more bug will go away because you will get warned that you are trying to push an incompatible type.

---

<div class="post-metadata">

**Author:** ![sigautomacao](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sigautomacao](https://forum.ionicframework.com/u/sigautomacao)\
**Post date:** [June 14, 2018, 8:05pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946/7 "2018-06-14T20:05:29Z")

</div>

```auto
interface Adicional {
  id: string;
  qtd: string;
}

```

Where to declare?

---

<div class="post-metadata">

**Author:** ![sigautomacao](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sigautomacao](https://forum.ionicframework.com/u/sigautomacao)\
**Post date:** [June 14, 2018, 8:22pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946/8 "2018-06-14T20:22:30Z")

</div>

I did as you told me, but it made a mistake:  
ERROR TypeError: Can not read property ‘qtd’ of undefined

```auto
import { ServerProvider } from '../../providers/server/server';

interface Adicional {
  id: string;
  qtd: string;
}

@IonicPage()
@Component({
  selector: 'page-delivery-addcart',
  templateUrl: 'delivery-addcart.html',
})

```

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:32pm UTC](https://forum.ionicframework.com/t/how-to-get-input-value-inside-ngfor/132946/9 "2021-07-19T21:32:15Z")

</div>

Closed on July 19, 2021, 9:32pm UTC


