2017-02-15 10 views
0

私はcheckboxがチェックされているかinputフィールドは、それが自動的に配列オブジェクト内に充填されますいくつかの値を持っているので、いつでも配列オブジェクトthis.enhancements[item.id] = { checked: false, qty: 0 };でフィールドをバインドしたいng-modelを使用して動作しません。NG-モデルは

以下は、私が現在取り組んでいるコードです。何が間違っているのかを教えてください。

home.ts

export class HomePage { 

    extras: any; 
    enhancements: any; 

    constructor(public navCtrl: NavController, public http: Http) { 
    this.http.get('https://www.example.com/api/enhance/11/?format=json').map(res => res.json()).subscribe(response => { 
     this.extras = response.Extras; 
     this.enhancements = {}; 
     this.extras.forEach(item => { 
      this.enhancements[item.id] = { checked: false, qty: 0 }; 
     }) 
    }); 
    } 

    onChange(){ 
    console.log(this.enhancements); 
    } 

} 

home.html

<ion-content padding> 
    <ion-grid> 
     <ion-row *ngFor="let item of extras" id="booking-enhancements-wrap-{{ item.id }}"> 
      <ion-col width-10> 
       <ion-checkbox (ionChange)="onChange()" ng-model="enhancements[item.id].checked" ng-checked="enhancements[item.id].checked"></ion-checkbox> 
      </ion-col> 
      <ion-col width-70>{{ item.name }}</ion-col> 
      <ion-col width-20><input type="number " id="qty-{{ item.id }} " style="width: 100%; " (input)="onChange()" ng-model="enhancements[item.id].qty" /></ion-col> 
     </ion-row>= 
    </ion-grid> 
</ion-content> 

答えて

3

あなたは次にあなたがNG-モデルに

を使用することはできませんionic2を使用している場合は、[(ngModel)]を使用する必要が

https://ionicframework.com/docs/v2/api/components/checkbox/Checkbox/

+0

は右に私を指していただき、誠にありがとうござい見ます方向。 –

+0

ようこそ、それが役立つ場合は右にマーク! –

1

この が

this.enhancements = {}; 

を交換してみてください