【发布时间】:2019-06-16 04:26:59
【问题描述】:
我无法在我的应用上显示我的 Firebase 中的数据。我对此真的很陌生,我不知道该怎么做。我在互联网上找不到任何解决方案。
这是我的打字稿代码:
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute, ActivatedRouteSnapshot } from "@angular/router";
import { Item } from "./item";
import { ItemService } from "./item.service";
import { EventData } from "tns-core-modules/data/observable";
import { Label } from "tns-core-modules/ui/label";
import { listener } from "@angular/core/src/render3";
const firebase = require("nativescript-plugin-firebase");
const firebaseWebApi = require("nativescript-plugin-firebase/app");
@Component({
selector: "ns-details",
moduleId: module.id,
templateUrl: "./item-detail.component.html",
})
export class ItemDetailComponent implements OnInit {
item: Item;
public oneway;
public stuff = firebaseWebApi.database().ref("/WaterStatus")
.once("value")
.then(result => console.log(JSON.stringify(result)))
.catch(error => console.log("Error: " + error));
constructor(
private itemService: ItemService,
private route: ActivatedRoute
) { }
ngOnInit(): void {
const id = +this.route.snapshot.params["id"];
this.item = this.itemService.getItem(id);
var onChildEvent = function(oneway) {
console.log("Water Status: " + JSON.stringify(oneway.value));
};
// listen to changes in the /users path
firebase.addChildEventListener(onChildEvent, "/WaterStatus").then(
function(listenerWrapper) {
var path = listenerWrapper.path;
var listeners = listenerWrapper.listeners;
}
);
firebase.getValue('/WaterStatus')
.then(result => console.log(JSON.stringify(result)))
.catch(error => console.log("Error: " + error));
}
}
这是我的html:
<ActionBar title="Details" class="action-bar"></ActionBar>
<FlexboxLayout flexDirection="column" class="page">
<FlexboxLayout class="m-15">
<Label class="h2" [text]="item.id + '. '"></Label>
<Label class="h2" [text]="item.name"></Label>
</FlexboxLayout>
<Label class="h3" [text]="item.role"></Label>
<!-- <Button text="Tap Me!" tap="onTap" class="btn btn-primary btn-active"></Button> -->
<br>
<br>
<Label class="h3 p-15" text='{{oneway}}' textWrap="true">{{oneway}}</Label>
<Label class="h3 p-15" text='{{stuff}}' textWrap="true"></Label>
<Label class="h3 p-15" text='{{last}}' textWrap="true">{{last}}</Label>
</FlexboxLayout>
如何在我的应用中显示我的数据?
有人说我应该做 Promise resolve,但我真的不知道如何将它与它集成。
截图:
【问题讨论】:
-
你在哪里看到
[object Promise]?你有这方面的 Playground 样本吗? -
我不认为我有它的游乐场样本。我还在赚取 nativescript,这是我第一次处理这样的事情。
-
我会用截图更新我的帖子
标签: firebase nativescript