Angular 扫描特定条形码时,firebase未加载JSON数据

Angular 扫描特定条形码时,firebase未加载JSON数据,angular,firebase,ionic-framework,Angular,Firebase,Ionic Framework,我需要帮助将JSON数据连接到我的应用程序,本地存储的JSON数据文件可以正常工作,但当我将其重定向到Firebase数据库时,它就不起作用了 这是处理条形码扫描仪工作方式的主代码 Home.ts import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import { BarcodeScanner } from '@ionic-native/barcode-scanner

我需要帮助将JSON数据连接到我的应用程序,本地存储的JSON数据文件可以正常工作,但当我将其重定向到Firebase数据库时,它就不起作用了

这是处理条形码扫描仪工作方式的主代码

Home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
import { Toast } from '@ionic-native/toast';
import { DataServiceProvider } from '../../providers/data-service/data-service';

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

  products: any[] = [];
  selectedProduct: any;
  productFound:boolean = false;

  constructor(public navCtrl: NavController,
    private barcodeScanner: BarcodeScanner,
    private toast: Toast,
    public dataService: DataServiceProvider) {
      this.dataService.getProducts()
        .subscribe((response)=> {
            this.products = response
            console.log(this.products);
        });
  }

  scan() {
    this.selectedProduct = {};
    this.barcodeScanner.scan().then((barcodeData) => {
      this.selectedProduct = this.products.find(product => product.sku[0] === barcodeData.text);
      if(this.selectedProduct !== undefined) {
        this.productFound = true;
        console.log(this.selectedProduct);
      } else {
        this.selectedProduct = {};
        this.productFound = false;
        this.toast.show('Product not found', '5000', 'center').subscribe(
          toast => {
            console.log(toast);
          }
        );
      }
    }, (err) => {
      this.toast.show(err, '5000', 'center').subscribe(
        toast => {
          console.log(toast);
        }
      );
    });
  }

}
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';

/*
  Generated class for the DataServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class DataServiceProvider {

  constructor(public http: Http) {
    console.log('Hello DataServiceProvider Provider');
  }

  getProducts(){
    return this.http.get('https://acis-676.firebaseio.com/0')
      .map((response:Response)=>response.json());
  }

}
从本地存储的json文件获取数据的部分,我还希望它能够访问firebase数据库

DataServiceProvider.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { BarcodeScanner } from '@ionic-native/barcode-scanner';
import { Toast } from '@ionic-native/toast';
import { DataServiceProvider } from '../../providers/data-service/data-service';

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

  products: any[] = [];
  selectedProduct: any;
  productFound:boolean = false;

  constructor(public navCtrl: NavController,
    private barcodeScanner: BarcodeScanner,
    private toast: Toast,
    public dataService: DataServiceProvider) {
      this.dataService.getProducts()
        .subscribe((response)=> {
            this.products = response
            console.log(this.products);
        });
  }

  scan() {
    this.selectedProduct = {};
    this.barcodeScanner.scan().then((barcodeData) => {
      this.selectedProduct = this.products.find(product => product.sku[0] === barcodeData.text);
      if(this.selectedProduct !== undefined) {
        this.productFound = true;
        console.log(this.selectedProduct);
      } else {
        this.selectedProduct = {};
        this.productFound = false;
        this.toast.show('Product not found', '5000', 'center').subscribe(
          toast => {
            console.log(toast);
          }
        );
      }
    }, (err) => {
      this.toast.show(err, '5000', 'center').subscribe(
        toast => {
          console.log(toast);
        }
      );
    });
  }

}
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';

/*
  Generated class for the DataServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class DataServiceProvider {

  constructor(public http: Http) {
    console.log('Hello DataServiceProvider Provider');
  }

  getProducts(){
    return this.http.get('https://acis-676.firebaseio.com/0')
      .map((response:Response)=>response.json());
  }

}
在json文件的卡片视图中显示数据的主主页。 Home.html

<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>

  <p>
    Internal Inventory System for 
  </p>
  <h1>
    <button ion-button color="dark" full round (click)="scan()">Start Scan</button>
  </h1>

  <ion-card *ngIf="productFound">
    <ion-card-header>
      <h2>Product Name: {{selectedProduct.name}}</h2>
    </ion-card-header>
    <ion-card-content>
      <ul>
        <p>SKU: {{selectedProduct.sku[0]}}</p>
        <p>Stock: {{selectedProduct.stock[0]}}</p>
      </ul>
    </ion-card-content>
  </ion-card>
</ion-content>

离子空白

企业内部盘存制度

开始扫描 产品名称:{{selectedProduct.Name}
    SKU:{{selectedProduct.SKU[0]}

    股票:{{selectedProduct.Stock[0]}