簡體   English   中英

離子| 不顯示Firebase的結果

[英]IONIC | Not showing results from firebase

是的...我不太確定怎么回事。 基本上-我只想顯示Firebase的結果。 這是我的代碼。

錯誤

TypeError: Cannot read property 'number' of undefined
    at Object.eval [as updateRenderer] (ng:///AppModule/HomePage.ngfactory.js:82:30)
    at Object.debugUpdateRenderer [as updateRenderer] (http://localhost:8100/build/vendor.js:14730:21)
    at checkAndUpdateView (http://localhost:8100/build/vendor.js:13866:14)
    at callViewAction (http://localhost:8100/build/vendor.js:14211:21)
    at execComponentViewsAction (http://localhost:8100/build/vendor.js:14143:13)
    at checkAndUpdateView (http://localhost:8100/build/vendor.js:13867:5)
    at callViewAction (http://localhost:8100/build/vendor.js:14211:21)
    at execEmbeddedViewsAction (http://localhost:8100/build/vendor.js:14169:17)
    at checkAndUpdateView (http://localhost:8100/build/vendor.js:13862:5)
    at callViewAction (http://localhost:8100/build/vendor.js:14211:21)

家庭

import { Component } from '@angular/core';
import { NavController, AlertController } from 'ionic-angular';
import { AddPage } from '../add/add';
import { AngularFireAction } from 'angularfire2/database/interfaces';
import { AngularFireDatabase } from 'angularfire2/database';

import firebase from 'firebase';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})
export class HomePage {

  teamList: any;

  public currentTeam = {};

  constructor(
    public navCtrl: NavController, 
    public afd: AngularFireDatabase) { 
    }

  add(){
    this.navCtrl.push(AddPage);
  }

  ionViewDidLoad(){
    const teamRef: firebase.database.Reference = 
    firebase.database().ref('/2771');
    teamRef.on('value', teamSnapshot => {
      this.currentTeam = teamSnapshot.val();
      console.log(this.currentTeam);
    });
  }



}

Home.html

<ion-header>
  <ion-navbar color="codeRed">
    <ion-title>
      Scouting
    </ion-title>
    <ion-buttons end>
      <button ion-button icon-only (click)="add()">
        <ion-icon name="add"></ion-icon>
      </button> 
    </ion-buttons>
  </ion-navbar>
</ion-header>

<ion-content class="home">
  <ion-card>
    <ion-card-header>
      Scouting
    </ion-card-header>

    <ion-list>
        <ion-item ngFor="let team of currentTeam | async">
          {{team.number}}
          {{team.match}}
        </ion-item>
    </ion-list> 

  </ion-card>
</ion-content>

package.json

{
  "name": "OfflineScoutingV6",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },
  "dependencies": {
    "@angular/common": "5.0.3",
    "@angular/compiler": "5.0.3",
    "@angular/compiler-cli": "5.0.3",
    "@angular/core": "5.0.3",
    "@angular/forms": "5.0.3",
    "@angular/http": "5.0.3",
    "@angular/platform-browser": "5.0.3",
    "@angular/platform-browser-dynamic": "5.0.3",
    "@ionic-native/core": "4.4.0",
    "@ionic-native/splash-screen": "4.4.0",
    "@ionic-native/status-bar": "4.4.0",
    "@ionic/storage": "2.1.3",
    "angular2-moment": "^1.7.1",
    "angularfire2": "^5.0.0-rc.4",
    "firebase": "4.8.0",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "rxjs": "5.5.2",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.1.6",
    "typescript": "2.4.2"
  },
  "description": "An Ionic project"
}

這是我第一次使用firebase和ionic。 任何幫助表示贊賞。 謝謝。 老實說,我不明白為什么這行不通。 我想我一切都正確。

嘗試這個

<ion-list>
        <ion-item ngFor="let team of currentTeam | async">
          {{team?.number}}
          {{team?.match}}
        </ion-item>
</ion-list> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM