1

I want to make dynamic ngmodel , but give me error this code. How can ı make dynamic ngModel?

veritext={};
<ion-item *ngFor="let ver of grafik" >  
   <input type="number" [(ngModel)]="veritext.ver.value" class="verigondertext" >
</ion-item>
1
  • 1
    give me error this code.. what error is it? Commented Aug 8, 2017 at 7:27

3 Answers 3

1

Base on your code you can try editing it like this.

instead of declaring {} object make it [] array . since you are looping the grafik

grafik=[]; 

lets assume you have this array

grafik = [
{ 
veritext: {   ver:'',  val:''  }
},
{ 
veritext: {   ver:'',  val:''  }
}  
]

on your html

 <ion-item *ngFor="let item of grafik" >  
     <input type="number" [(ngModel)]="item.veritext.val">
 </ion-item>
Sign up to request clarification or add additional context in comments.

Comments

0

@ahmet

Please use following code

veritext={};
<ion-item *ngFor="let ver of grafik" >  
  <input type="number" [(ngModel)]="ver.value" class="verigondertext" >
</ion-item>

Make sure if 'value' key is not able in grafik array then you get error.

I hope it's work fo you

Comments

0

I believe that this will solve your problem :)

   [(ngModel)]="veritext[ver.value]"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.