【问题标题】:How to display data in HTML using Firebase and Ionic 3如何使用 Firebase 和 Ionic 3 在 HTML 中显示数据
【发布时间】:2018-03-14 23:52:55
【问题描述】:

我想显示来自 Firebase 数据库的数据,但它不起作用。 我正在使用 Ionic 3

我的 TypeScript 文件上的代码。

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

HTLM

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

我尝试发出警报以显示问题并且它有效,但 h4 内的显示无法正常工作。

【问题讨论】:

    标签: angular typescript firebase ionic3 angularfire2


    【解决方案1】:

    您需要在全局范围内声明question,并同时使用fat arrow function,如下所示。

    .ts

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

    }

    .html

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

    【讨论】:

      猜你喜欢
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 2018-09-14
      • 2019-11-03
      • 1970-01-01
      • 2017-12-12
      • 2019-05-24
      • 2021-12-20
      相关资源
      最近更新 更多