简体   繁体   English

如何使用Firebase和Ionic 3以HTML显示数据

[英]How to display data in HTML using Firebase and Ionic 3

I want to display a data from database from Firebase, but it's not working. 我想显示Firebase数据库中的数据,但无法正常工作。 I'm using Ionic 3 我正在使用Ionic 3

Code on my TypeScript file. 我的TypeScript文件上的代码。

let questionRef= firebase.database().ref().child("Test");
  questionRef.on('value', function(snapshot){
    let question = snapshot.val();
  });

HTLM HTLM

<h4 style="text-align:center;">{{question}}</h4>

I tryied to do an alert to show the question and it worked, but the display inside the h4 is not working. 我试图发出警报以显示问题,该问题已解决,但h4内的显示不起作用。

You need to declare question globally and also use fat arrow function as shown below. 您需要全局声明question ,还需要使用fat arrow function ,如下所示。

.ts .ts

question:string="";

constructor(){

let questionRef= firebase.database().ref().child("Test");
  questionRef.on('value', (snapshot)=>{
    this.question = snapshot.val();
  });

} }

.html .html

<h4 style="text-align:center;">{{question}}</h4>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM