[英]Angular not pulling data through Angularfire2
I have been having a problem getting data back from the Real time Database on firebase. 我一直在从Firebase的实时数据库获取数据时遇到问题。 Everything is set correctly, the Read and Write permissions are public so I don't have to authenticate.
一切设置正确,读写权限是公共的,因此我不必进行身份验证。
npm compiles successfully. npm编译成功。 So the code is good (Angular-CLI).
因此,代码是好的(Angular-CLI)。 I tried exactly what is on the GitHub page as far as the documentation goes.
就文档而言,我尝试了GitHub页面上的内容。
When I interpolate pulling data from an Object the return on the front end is Null. 当我插值从对象中提取数据时,前端的返回值为Null。 When I do the same for a List the return is blank.
当我对列表执行相同操作时,返回为空白。 *ngFor won't even work.
* ngFor甚至无法工作。
Anyone has the same problem or could help? 任何人都有同样的问题或可以帮助吗?
The code looks like this. 代码看起来像这样。 That's a direct copy from the documentation.
这是文档的直接副本。
My database actually has no label that says " Items " as per db.list('items') . 我的数据库实际上没有根据db.list('items')标注“ Items”的标签。 I dont think that would be the issue, but would that create a problem?
我不认为这是问题,但是会造成问题吗?
import { Component } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
@Component({
selector: 'app-root',
template: `
<ul>
<li *ngFor="let item of items | async">
{{ item | json }}
</li>
</ul>
`,
})
export class AppComponent {
items: Observable<any[]>;
constructor(db: AngularFireDatabase) {
this.items = db.list('items').valueChanges();
}
}
The data in firebase has this structure.. Firebase中的数据具有此结构。
[
{"THIS" : string , "THAT" : string},
{"THIS" : string , "THAT" : string}
]
That's what the file looks like before I uploaded. 这就是我上传之前文件的外观。
I think you forgot to create the items
collection. 我认为您忘记了创建
items
集合。
You are subscribed to the items
collection here: 您在此处订阅了
items
集合:
this.items = db.list('items').valueChanges();
Try to import this one and see if you get some results: 尝试将其导入,看看是否得到一些结果:
{
"items": [
{
"THIS": "test",
"THAT": "test"
},
{
"THIS": "test",
"THAT": "test"
}
]
}
In firebase it looks like: 在firebase中,它看起来像:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.