簡體   English   中英

我無法使用異步管道從Firebase數據庫檢索數據

[英]I cannot retrieve data from firebase database using async pipe

我通過觀看Mosh Hamedani的Udemy課程來學習Angular 4。 在他的應用程序中建立類別列表時,他使用了AngularFireBase方法“列表”。 我試圖復制代碼,但是異步管道未顯示任何結果。 我試圖做我的研究,但徒勞無功。

我還閱讀了一些內容的更改( https://github.com/angular/angularfire2/blob/master/docs/version-5-upgrade.md )。 但是,我的應用程序似乎根本找不到valueChanges方法。 同樣,db.list方法根據VS Code智能許可證返回我需要的值。

我返回類別的課程

import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';

@Injectable()
export class CategoryService {

constructor(private db: AngularFireDatabase) { }

getCategories() {
     return this.db.list('/categories');
}

}

我嘗試從其使用html模板中的類別的類

import { Component } from '@angular/core';
import { CategoryService } from '../../category.service';

@Component({
  selector: 'app-product-form',
  templateUrl: './product-form.component.html',
  styleUrls: ['./product-form.component.css']
})
export class ProductFormComponent {
  categories$;

  constructor(categoryService: CategoryService) {
    this.categories$ = categoryService.getCategories();
  }
}

html模板

<div class="form-group">
  <label for="category">Category</label>
    <select id="category" class="form-control">
      <option value=""></option>
      <option *ngFor="let c of categories$ | async" [value]="c.$key">
        {{ c.name }}
      </option>
    </select>
</div>

請幫助,因為我在這里很絕望

因此,需要2周的調試和解決方法的思考。 Angular 4.0.0可以與angularfire2 4.0.0-rc.1和firebase 4.2.0一起正常工作。 問題出在我的Firebase數據庫結構上-我又一次嵌套了類別字段。 耶穌。

暫無
暫無

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

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