Я не могу показать свои данные из базы данных о пожарной безопасности в моем приложении.Я действительно новичок в этом, и я не знаю, что делать.Я не могу найти никакого решения для этого в Интернете.
Это мой машинописный код:
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, но я не знаю, как интегрировать его с этим.
снимок экрана:
снимок экрана