Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • My template shows up blank but there is no errors in console. I added console.log(this.questions, this.question) to the top of nextQuestion function and found out that the array is initialized but Observable is undefined until I first click Next. After clicking, my md-card is still blank. The console, however, now says Scalar Observable. If I keep clicking next, I keep getting the same observable back. The first one in my list. Commented Sep 4, 2017 at 5:07
  • @LandonWaldner I just updated answer. I added ngIf to make sure that we have data back from firebase before rendering it, and also correcting async in the template (If it works, you can remove either *ngIf or async from question object. Also, I added a console.log to see data coming back from firebase. If this solution not working, please send me the console.log output as I don't know about your data structure. Commented Sep 4, 2017 at 10:45
  • ngOnInit() { this.index = 0; this.fbDatabase.getFirebaseList('/questions').subscribe( (res) => { if (res) { this.questions = res; this.nextQuestion(this.index); } } ); } nextQuestion(i: number) { if (i >= this.questions.length) { this.index = i = 0; } this.question = Observable.of(this.questions[i]); this.index++; } Commented Sep 4, 2017 at 15:03
  • Oops. I was able to get it to working by tweaking the above code a little. I appreciate all of your help. Especially the idea of casting to a regular Observable. I tried to upvote but I have less than 15 reputation so it didn't count. Commented Sep 4, 2017 at 15:04
  • Great to hear that it works. Even better when you know how to tweak it. If you think my answer helps, then tick it as correct answer. If you are proud of your tweaking, just post your own answer so that others can learn. Commented Sep 4, 2017 at 21:01