标签: angularfire5

在firestore和商品实践中插入封装的物体

我有一个关于在angularfire 的firestore中插入对象的问题:

我的对象 Person.ts

name: String
age: Number
//--constructor--
//--getters and setters--
Run Code Online (Sandbox Code Playgroud)

如果我这样做,请插入:(但这是一个好习惯吗?)

[person.component.ts]
      this.db.collection("person").add({
              name: this.person.$nome,
              age: this.person.$email
          })
    ...
Run Code Online (Sandbox Code Playgroud)

但如果我尝试:

    [person.component.ts]
         this.db.collection("person").add({
                     Person: this.person
//or this this.person
                  })
Run Code Online (Sandbox Code Playgroud)

我在浏览器控制台中收到此错误:

使用无效数据调用函数 DocumentReference.set()。不支持的字段值:在 new FirestoreError (error.js:149) 处的自定义 Person 对象(在字段 Person 中找到)

angularjs firebase-realtime-database google-cloud-firestore angularfire5

5
推荐指数
1
解决办法
643
查看次数

Firestore:检索单个文档

我想从 Firestore 检索单个文档。所以我的意思不是集合中的文档列表(我知道怎么做)。假设我知道文档的键值对之一,我想查找文档并将其检索到 Angular 4 中。

interface Occupations {
	duration: number;
	id_entity: number;
	id_job: number;
	id_user: number;
	salary: number;
	start_time: number;
}

occupationDoc:AngularFirestoreDocument<Occupations>;
occupation: Observable<Occupations>;
Run Code Online (Sandbox Code Playgroud)
<h1>A specific post:</h1>

  <h3>{{ (occupation | async)?.salary }}</h3>
  <p>{{ (occupation | async)?.id_user }}</p> 
  <p>{{ (occupation | async)?.duration }}</p> 
  <p>{{ (user | async)?.lastName }}</p> 
Run Code Online (Sandbox Code Playgroud)

javascript rxjs angular google-cloud-firestore angularfire5

5
推荐指数
1
解决办法
9056
查看次数

如何在 angularFire 2 Account Create with email 中实现 reCaptcha?

我正在尝试使用 angularFire 2 在 firebase 中登录并创建帐户。电话登录有一个运行良好的 reCaptcha 字段。使用电子邮件和密码创建帐户也工作正常,但我想在创建表单(如电话登录功能)中使用 reCaptcha,但我没有找到方法,可以在 angularFire 中使用电子邮件和密码创建帐户并使用 reCaptcha 验证。我也尝试过文档,但没有这样的。如果 Angular Fire 2 中有类似的选项,请帮助我。我正在使用"angularfire2": "^4.0.0-rc.1",

firebase angularfire2 angular angularfire5

5
推荐指数
0
解决办法
236
查看次数

订阅一个 AngularFireObject

我刚刚升级到 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

5
推荐指数
1
解决办法
3048
查看次数

Angular&AngularFire 5从文档中检索数据

我在用什么

  • 角度5
  • AngularFire5
  • Firebase和Firestore

我正在努力实现的目标

我目前正在使用Google Firebase的新Firestore在学习角度的同时创建一个新应用。我的应用程序当前创建一个名为Links的集合,并创建一个具有自定义ID的新文档,该自定义ID在用户添加链接(即shorturl)时生成,该文档中包含4个字段:

  • uid
  • 网址
  • 短网址
  • 点击次数

我希望应用程序查询url字段中文档内的数据。

到目前为止我有什么

我已经创建了正确文档的路径:

  linkCollection: Observable<{}>;
  constructor(private afs: AngularFirestore, private router: Router) {
      this.path = this.router.url.replace('/','');
      afs.collection('Links').doc(this.path).valueChanges();
  }
Run Code Online (Sandbox Code Playgroud)

我被困在哪里

这可能是一个简单的解决方案,但我不确定如何获取url字段。我拥有的代码能够检索该文档,并且在另一部分中使用类似的方法来检索所有想法,并使用* ngFor显示数据,但不确定如何在ts文件而不是模板中进行操作。

firebase angularfire2 angular google-cloud-firestore angularfire5

3
推荐指数
1
解决办法
4365
查看次数

无法使用 angularfire2 在 Angular 6 应用程序中访问多个 Google Firestore 数据库

我尝试通过 angularfire2 包从我的 Angular 6 应用程序访问多个 Google Firestore 数据库。

我在 app.module.ts 中初始化了多个 AngularFireModule 实例,但找不到访问两个数据库的方法:

  @NgModule({
  declarations: [
	...
  ],
  imports: [
	...
    AngularFireModule.initializeApp(coolStoreConfig, 'coolStore'),
    AngularFireModule.initializeApp(perfectStoreConfig, 'perfectStore'),
	...
  ],
  ...
 })
Run Code Online (Sandbox Code Playgroud)

任何的想法?

angularfire2 angular google-cloud-firestore angularfire5

2
推荐指数
1
解决办法
898
查看次数

如何获取具有id的特定文档数据?| AngularFire 5.1.1 | Cloud Firestore | 文件资料

我正在使用数据访问服务从Firebase Firestore获取数据。

如何使用snapshotChanges()方法获取具有ID的特定文档数据

getProduct(id: number): Observable<Product> {
    this.productsDocuments = this.angularfirestore.doc<Product>('products/' + id);
    this.product = this.productsDocuments.snapshotChanges().pipe(
      map(changes => changes.map(a => {
        const data = a.payload.doc.data() as Product;
        const id = a.payload.doc.id;
        return { id, ...data };
      }))
    );
    return this.product
Run Code Online (Sandbox Code Playgroud)

我想要this.product返回文档值和文档ID

谢谢!!

firebase angular google-cloud-firestore angularfire5

2
推荐指数
1
解决办法
1751
查看次数

Firestore:如何查询文档集合内的地图对象?

我的目标:

网络应用程序(类似于Google云端硬盘)有2个屏幕。

第一个屏幕是“我的故事”,其中显示了我是所有者的所有故事文档。

第二个屏幕是“与我共享”,其中显示了我是读者,作家或评论者的所有故事文档。

我们有这个/ stories / {storyid}

{
  title: "A Great Story",
  content: "Once upon a time ...",
  roles: {
    alice: "owner",
    bob: "reader",
    david: "writer",
    jane: "commenter"
    // ...
  }
}
Run Code Online (Sandbox Code Playgroud)

完整的数据结构参考:https : //firebase.google.com/docs/firestore/solutions/role-based-access

问题:如何编写以下查询以实现上述目标?

db
.collection('stories')
.where(`roles.${uid}`, '==', 'owner')
Run Code Online (Sandbox Code Playgroud)

上面的查询不起作用,因为它将要求Firestore索引role.alice,roles.bob,roles.david,roles.jane和role。[all_uid]。


编辑#1:找到相关帖子(无答案),询问有关带角色的Firestore查询

firebase angularfire2 google-cloud-firestore angularfire5

1
推荐指数
2
解决办法
2948
查看次数