Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

How to use ngFor with ngModel

$
0
0

@RaulAndrade wrote:

I'm trying to get the value of a checkbox I generated with a * ngFor with firebase.

I get te value with [(ngModal)]="var", but I can't put it question.question because that variable has to be created in the .ts(Angular)

How to use ngFor with ngModel to get the value of each element that is created in the DOM

My view:

<div class="Pregunta" *ngFor="let pregunta of preguntas | async">
        <ion-row class="PreguntaTitulo" >
          <ion-col coll-12>{{pregunta.pregunta}}</ion-col>
        </ion-row>
        <ion-list radio-group [(ngModel)]='pregunta.pregunta' >
        <ion-row class="Respuesta">
          <ion-col col-4 col-sm>
            <ion-item>
              <ion-label color='secondary'>Bueno</ion-label>
              <ion-radio [value]="bueno" color='secondary'></ion-radio>
            </ion-item>
          </ion-col>
          <ion-col col-4 col-sm>
            <ion-item>
              <ion-label color='amarillo'>Regular</ion-label>
              <ion-radio [value]="regular" color='amarillo'></ion-radio>
            </ion-item>
          </ion-col>
          <ion-col col-4 col-sm>
            <ion-item>
              <ion-label color='danger'>Malo</ion-label>
              <ion-radio [value]="malo" color="danger"></ion-radio>
            </ion-item>
          </ion-col>
        </ion-row>
        </ion-list>
</div>

My ts:

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
@Component({
  selector: 'page-checklist',
  templateUrl: 'checklist.html',
})
export class ChecklistPage {

 //if i creat a element with [(ngModel)]= 'var', I create that variable here,  example( var:any ; )
 // and I can use it in any method
 //How creat the var for ngModel

  preguntas: FirebaseListObservable <any>;

  constructor(public navCtrl: NavController,
    public navParams: NavParams,
    public afDB: AngularFireDatabase) {
      this.preguntas = afDB.list ("/vehiculo");
    }

  ionViewDidLoad() {}

}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>