Я новичок в firebase и angular, пытаясь понять, что я создал данные в firebase и теперь хочу получить в angular 5. Но это не работает.
Структура данных Firebase:
category.service.ts:
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class CategoryService {
constructor(private db: AngularFireDatabase) { }
getCategories(){
return this.db.list('/categories').valueChanges();
}
}
Product-form.component.ts
import { CategoryService } from './../../category.service';
import { Component, OnInit } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
@Component({
selector: 'app-product-form',
templateUrl: './product-form.component.html',
styleUrls: ['./product-form.component.css']
})
export class ProductFormComponent implements OnInit {
categories$; // Observable
constructor(private categoryService: CategoryService) {
}
ngOnInit() {
this.categories$ = this.categoryService.getCategories();
console.log(this.categories$);
}
}
product-form.component.html
<select class="form-control" name="" id="category">
<option value=""></option>
<option *ngFor="let c of categories$ | async" [value]="c.$key">
{{c.name}}
</option>
</select>
Ошибка в консоли, которую я получаю:
Скажите, пожалуйста, что не так с моим кодом.