Goal: I have a quiz component and I want to be able to show one question at a time in my template. The user can show the next question when they click the Next button.
Problem: I have a FirebaseListObservable that contains the entire list of questions. How can I render only one at a time to my template. I pasted below what I have for code so far. It renders the entire list. I don't know where to go from here, partly due to my beginner's level of RxJS knowledge.
import { Component, OnInit } from '@angular/core';
import { FirebaseService } from '../../firebase.service';
import { Observable } from 'rxjs/Observable';
import { Question } from '../../model/question';
@Component({
selector: 'app-quiz',
template: `
<md-grid-list cols="1" rowHeight="2:1">
<md-grid-tile>
<md-card *ngFor="let question of questions$ | async">
<md-card-header>
<md-card-title>{{question?.course}}</md-card-title>
<md-card-subtitle>{{question?.chapter}}</md-card-subtitle>
</md-card-header>
<md-card-content>
<p>{{question?.question}}</p>
</md-card-content>
<md-card-actions>
<button md-button>See Answer</button>
<button (click)="nextQuestion(question)" md-button>Next
Question</button>
</md-card-actions>
</md-card>
</md-grid-tile>
</md-grid-list>
`,
styles: [`.example-card { width: 400px;}`]
})
export class QuizComponent implements OnInit {
questions$: Observable<Question[]>;
constructor(private fbDatabase: FirebaseService) { }
ngOnInit() {
this.questions$ = this.fbDatabase.getFirebaseList('/questions');
}
nextQuestion() {
}
}