【发布时间】:2019-02-04 23:46:19
【问题描述】:
我已经完成了搜索,它获取数组,然后在输入时过滤它的名称。如果我写静态,一切都很好:
export class AddComponent {
protected dataService: CompleterData;
protected searchData = [
{name: '84A4DA'},
{name: '846ASD'},
{name: '8444AS'},
]
constructor(private completerService: CompleterService, private router: Router, public back: BackService,
) {
this.dataService = completerService.local(this.searchData, 'name', 'name');
}
但是当我尝试从 db firebase 制作我的 searchData 时:
getArray(): void {
this.afDatabase.list('/imones')
.valueChanges()
.subscribe(res => {
console.log(res)//should give you the array of percentage.
this.array = res;
})
}
this.searchData = this.back.getArray();
constructor(private completerService: CompleterService, private router: Router, public back: BackService,
) {
this.dataService = completerService.local(this.searchData, 'name', 'name');
}
我得到错误:
如何解决?
【问题讨论】:
-
你能为此创建一个堆栈闪电战吗?并添加
completerService的代码 -
完成服务是 ng2-completer 模块 - 不是我的。
-
getArray() 的返回类型是 void 类型,因此 searchData 是 void 类型,而不是数组。而是写,this.searchData = res;在订阅中,因为那是您的数组所在的位置。
-
它应该是什么样子?搜索数据 = ??
-
我的意思不是我改成searchdata = res的时候,而是之前声明的时候
标签: angular typescript firebase firebase-realtime-database