标签: angularfire2

Angular2 Firebase获取当前用户

我真的很难理解如何获取登录用户的当前用户ID并按该用户ID过滤列表.

我可以很容易地获得用户ID,但是在获得客户列表的电话时似乎没有.

如果有人可以协助或指出我正确的方向,我将不胜感激.

验证服务

import { Injectable } from "@angular/core";
import { AngularFire, AuthProviders, AuthMethods, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';
import { UserModel } from '../users/models/user.model';

@Injectable()
export class AuthenticationService {

  public displayName: string;
  public userKey: string;
  public user: UserModel;

  constructor(public af: AngularFire) {
    this.af.auth.subscribe(
      (auth) => {
        if (auth != null) {
          this.user = this.af.database.object('users/' + auth.uid);
          this.userKey = auth.uid;
        }
      });
  }

  logout() {
    return this.af.auth.logout();
  }

  loginWithEmail(email, password) {
    return this.af.auth.login({
      email: email,
      password: password,
    },
      { …
Run Code Online (Sandbox Code Playgroud)

firebase firebase-authentication angularfire2 angular

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

AngularFire2无法绑定到'ngForAs',因为它不是'li'的已知属性

我试图使用*ngFor循环从firebase数据库中循环出一个简单的字符串列表.但是我在控制台中收到一条错误消息:

Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngForAs' since it isn't a known property of 'li'. ("  <ul>
    <li [ERROR ->]*ngFor="let item as items | async">
        {{item.$value}}
    </li>
"): AppComponent@1:7
Property binding ngForAs not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("  <ul>
    [ERROR ->]<li *ngFor="let item as items | async">
        {{item.$value}}
    </li>
"): AppComponent@1:3 ; Zone: <root> ; …
Run Code Online (Sandbox Code Playgroud)

firebase typescript ngfor angularfire2 angular

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

如何在firestore中处理承诺

这是我的代码来检查a中doc是否存在collections

this.shopCollection = this.afs.collection<Shop>('shops', ref => {
  return ref.where('fulladdress', '==', myString)
});
Run Code Online (Sandbox Code Playgroud)

我不知道为什么我不能用.then(),并.catch()用此方法.当我传递一个字符串进行查询,如果没有找到结果我怎么知道?

我使用的angularfire2版本^5.0.0-rc.1angular ^4.2.4firebase ^4.5.0.

请帮忙.

javascript promise firebase angularfire2 google-cloud-firestore

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

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

模块'AppModule'导入的意外值'AngularFireDatabase'.请添加@NgModule注释

App.Module.ts

import { AngularFireDatabase } from 'angularfire2/database';

imports: [    
    AngularFireDatabase
]
Run Code Online (Sandbox Code Playgroud)

出于某种原因,当我不需要时,它一直要求我添加一个@NgModule注释.我是Firebase的新手.

我已经尝试将其添加到我的tsconfig.json文件中以查看它是否可以获取angularfire2模块但仍然没有运气:

"paths": {
  "@angular/*": [
    "../node_modules/@angular/*"
  ],
Run Code Online (Sandbox Code Playgroud)

angularfire2 angular

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

在Cloud Firestore中检查文档字段以查找特定值

我想用自定义用户名创建用户注册.我将用户的用户名存储在Firestore中的用户文档中.如何验证用户集中已存在的用户名?

也许有人已经有反应表格验证的片段?

firebase google-cloud-datastore angularfire2 angular google-cloud-firestore

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

你能在angularfire2中使用firebase"可调用函数"吗?

是否可以与AngularFire2一起使用"可调用函数"?

由于AngularFireModule已经调用了initializeApp,我不知道如何按照这里的说明操作?

我想我不应该多次调用initializeApp()?

firebase angularfire2

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

AngularFire2的Firebase数据库事务

我们应该如何在AngularFire2的5.0.0-rc.7版本中使用事务?

我目前有以下内容:

this.db.database.ref('path/to/my/count').transaction(count => {
      console.log(count);
      return count + 1;
    });
Run Code Online (Sandbox Code Playgroud)

但是,即使Firebase数据库中的值设置为1,计数也始终以null的形式传递给事务方法的回调参数。

正确的做法是什么?

firebase firebase-realtime-database angularfire2 angular

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

如何通过Angularfire或Firebase获取serverTimestamp

我找不到从Firestore获取serverTimestamp的方法。既可以使用Firestore本身,也可以使用angularfire。

我发现很多github问题与解决方案有关,这是行不通的。我猜那是因为版本不同吗?

"@firebase/app": "^0.1.10",
"angularfire2": "^5.0.0-rc.6.0",
"firebase": "^4.13.1",
Run Code Online (Sandbox Code Playgroud)

我尝试过的代码替代方法:

import * as firebase from 'firebase';
firebase.firestore.FieldValue.serverTimestamp();
Run Code Online (Sandbox Code Playgroud)

错误TypeError:无法读取未定义的属性'FieldValue'

import * as firebase from 'firebase';
firebase.database.ServerValue.TIMESTAMP;
Run Code Online (Sandbox Code Playgroud)

错误TypeError:无法读取未定义的属性'ServerValue'

constructor( private afs: AngularFirestore ) { }
this.afs.firestore.FieldValue.serverTimestamp();
Run Code Online (Sandbox Code Playgroud)

类型“ FirebaseFirestore”上不存在属性“ FieldValue”。

angularfire2 angular

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

类型'void'Angular 6上不存在属性'pipe'

我不明白问题的原因.我的代码来自ServiceFile,我得到错误

  1. 类型'void'上不存在属性'pipe'.
  2. 类型"{}"上不存在属性"$ key".

https://i.imgur.com/0m0HmKi.png

import { Injectable } from '@angular/core';
import { AngularFireDatabase, AngularFireList } from '@angular/fire/database';
import { switchMap } from 'rxjs/operators';
import { Observable } from 'rxjs';
@Injectable({
  providedIn: 'root'
})
export class CoursesService {

  constructor(private af: AngularFireDatabase) { }

  findAllCourses(): AngularFireList<any> {
    return this.af.list('courses');
  }

  findCourseDtl(coursUrl:string){
   this.af.list('courses', ref => ref.orderByChild('url').equalTo(coursUrl)).valueChanges()
  }

  findLessonsForCours(coursUrl:string): Observable<any>{
    return this.findCourseDtl(coursUrl)
   .pipe(switchMap(course => this.af.list('lessonsPerCourse/'+ course.$key ).valueChanges()));


}

}
Run Code Online (Sandbox Code Playgroud)

rxjs typescript angularfire angularfire2 angular

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