我想使用ngForAngular 2将 Firebase 查询的结果绑定到我的模板。这很容易在下面实现。
成分:
export class FeaturedThreadsComponent {
threads: FirebaseListObservable<any[]>;
qualitySubject: Subject<any>;
constructor(af: AngularFire) {
this.qualitySubject = new Subject();
this.threads = af.database.list('/threads', {
query: {
orderByChild: 'quality',
endAt: 5
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
模板:
<div *ngFor="let thread of threads | async">
{{thread.title}}
</div>
Run Code Online (Sandbox Code Playgroud)
但是如果我想使用ngFor嵌套在模板中的另一个指令来列出子对象的键......
<div *ngFor="let thread of threads | async">
{{thread.title}}
<div *ngFor="let participant of thread.participants">
{{participant.$key}}}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我收到控制台错误, Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports …
我有一个设置,我可以在 firebase 中查询用户最喜欢的帖子列表。
基本上,首先我查询用户喜欢,然后为每个喜欢获取相应的帖子 - 所有这些都在一个可观察的序列中。
当用户不喜欢唯一留下的帖子时,就会出现问题。在这种情况下(当 likes 数组变空时)不会从 observable 中触发任何内容并且视图不会更新(总是至少有一个帖子存在)。
一方面,这种行为似乎合乎逻辑且可以理解,但另一方面,即使 switchMap 的输入为空,我也不知道如何使最终的 Observable 发出。也许应该改变运营商。
getUserFavourites(userId = ""):Observable<Post[]>
{
if (!this.userFavourites$) {
this.userFavourites$ = this.af.database.list('/ranks_by_user/' + userId, {
query: {
limitToFirst: 50
}
}) //Emits value here (even empty array)
.switchMap((likes: any[]) => Observable.combineLatest(
likes.map(like => this.af.database.object("/posts/" + like.$key).first())
)) //Does not emit new value here if likes array was empty
.map(p => {
return p.map(cit => Post.unpack(p));
}).publishReplay(1).refCount()
}
return this.userFavourites$;
}
Run Code Online (Sandbox Code Playgroud) 我阅读了 Firebase 中的多对多关系问题,
这里描述了如何在 firebase(nosql 数据库)中创建或构建多对多关系,这很容易,
companyContractors
companyKey1
contractorKey1: true
contractorKey3: true
companyKey2
contractorKey2: true
contractorCompanies
contractorKey1
companyKey1: true,
companyKey2: true
contractorKey2
companyKey2: true
contractorKey3
companyKey1: true
Run Code Online (Sandbox Code Playgroud)
但是当我想获得所有承包商的特定公司时,我可以只使用一个请求吗?因为在这种情况下,我只得到 id 列表,在那里之后,使用 js 循环或 forEach,我做了多个请求。
通常在其他 API 上,我只使用
URL/contractor/:id/company or
URL/company/:id/contractors
Run Code Online (Sandbox Code Playgroud)
如何在firebase上做到这一点?
有一个使用angular2,angularfire2的例子会很酷,
谢谢
javascript nosql firebase firebase-realtime-database angularfire2
我想使用 firebase 身份验证将电子邮件验证码发送到用户的电子邮件。我正在使用(sendEmailVerification)方法,但 firebase 向用户的电子邮件发送验证链接。如果是,是否可以将验证码发送到用户的电子邮件,那么如何完成?
我正在使用 Angular 4 和 firebase angularfire2
谢谢。
如何获取登录用户?
我这样做: console.log('登录...'); this.afAuth.auth.signInWithEmailAndPassword(this.email, this.password);
但是文档并不清楚如何让用户进入代码。它们在模板中显示了一种方式,但我需要存储当前用户。
firebase firebase-authentication angularfire2 google-cloud-firestore
我刚刚升级到 AngularFire2 rc 5.0。
我修改了我的代码,使其与新类型和功能相匹配,但是在尝试订阅 a 时出现以下错误.object(path):
Property 'subscribe' does not exist on type 'AngularFireObject'
Run Code Online (Sandbox Code Playgroud)
我的代码如下。
供应商:
getEvent(id: string): AngularFireObject<any> {
let path = `/events/${id}`;
return this.af.object(path).valueChanges();
}
Run Code Online (Sandbox Code Playgroud)
页:
...
event$: AngularFireObject<any>;
...
// Retrieve event's info
this.event$ = this.eventService.getEvent(this.id);
// Retrieve event's ownership info
let subscription = this.event$.subscribe(event => {
this.owner$ = this.userService.getUserPublicInfo(event.owner);
});
Run Code Online (Sandbox Code Playgroud)
任何的想法?
observable ionic-framework angularfire2 angular angularfire5
在我的 Angular 应用程序中,Firebase 返回一个显示bad-app-name为代码的错误。我在 angular 应用程序中使用 angularfire2。
我已经仔细检查了 Firebase 配置,没问题,那么如何解决这个错误。
app.components.ts
import { Component, OnInit } from '@angular/core';
import { FormsModule, NgForm } from "@angular/forms";
import { AngularFireDatabase } from "angularfire2/database";
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent{
isLoggedIn: boolean = false;
courses: any[];
constructor(public db: AngularFireDatabase) {
db.list('/Courses').valueChanges().subscribe(courses => {
this.courses = courses;
console.log(this.courses);
});
}
login() {
this.isLoggedIn = !this.isLoggedIn;
}
user:any;
saveData(formData) {
if (formData.valid) …Run Code Online (Sandbox Code Playgroud) 这是保存在数据库中并重用 angularfire2 返回的 urlgetDownloadURL()而不是getDownloadURL()每次需要显示来自 Firebase 存储的图像时执行的好做法吗?
如果我getDownloadURL()在组件中使用,则每次访问组件时都会重新加载图像。我想避免这种情况。如果我在上传图像后将 url 保存在我的数据库中,然后每次需要显示图像时都使用这个 url,这可以解决问题。但是,这可能不是正确的方法,Firebase 存储可能会在某个时候更新 url。
我有以下查询
selectedUser$: AngularFirestoreDocument<any>;
this.selectedUser$ = this.userCollection.ref.where('uid', '==', key)
Run Code Online (Sandbox Code Playgroud)
投掷错误
类型“查询”不可分配给类型“AngularFirestoreDocument”。“查询”类型中缺少属性“ref”。
我试过
this.selectedUser$ = this.userCollection.ref.where('uid', '==', key).get()
Run Code Online (Sandbox Code Playgroud)
没有成功
基本上,我希望查询返回 firestore 文档
angularfire2 ×10
angular ×8
firebase ×8
javascript ×2
angularfire5 ×1
nosql ×1
observable ×1
rxjs ×1