Html 无效参数:';[对象对象]';对于管道';异步管道&x27;错误时
我想从数据库中获取一些数据 这是我的服务Html 无效参数:';[对象对象]';对于管道';异步管道&x27;错误时,html,angular,firebase,Html,Angular,Firebase,我想从数据库中获取一些数据 这是我的服务 export class CategoryService { constructor(private db: AngularFireDatabase) { } getCategories(){ return this.db.list('/categories'); } $Component代码 export class ProductFormComponent implements OnInit { categories$;
export class CategoryService {
constructor(private db: AngularFireDatabase) { }
getCategories(){
return this.db.list('/categories');
}
$Component代码
export class ProductFormComponent implements OnInit {
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>
类别
{{c.name}}
Firebase库返回承诺。让它们返回可见的
import{from}来自'rxjs/operators';
导出类类别服务{
构造函数(私有数据库:AngularFireDatabase){}
getCategories(){
从(this.db.list('/categories')返回;
}
试试这些代码,它应该可以工作
import {Injectable} from '@angular/core';
import {AngularFireDatabase} from '@angular/fire/database';
import {from} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class CategoryService {
constructor(private db: AngularFireDatabase) {}
getCategories() {
return from(this.db.list('/categories').valueChanges());
}
}
不幸的是,它对我不起作用,因为在尝试导入“from”时出现语法错误@mateimil是的,我添加了一个不必要的
@
,抱歉,将其删除。感谢您回答了一个仍然在寻找正确答案的老问题,但如果您提供一些解释,这将对OP和其他人有所帮助。比如为什么您没有回答你认为这是可行的,你做了什么改变,为什么,等等