标签: angularfire2

Firebase ionic2-rc0 和 rollup - “rollup:强烈建议不要使用 `eval`”

我已将我的 ionic 应用程序从 beta 11 更新到 rc0。所以这意味着我已经从 Angular2 RC4 切换到 Angular2 stable,从 TypeScript 1.8 切换到 2,并使用 rollupjs 模块捆绑器。

我已经根据这篇博客文章配置了 AngularFire2: Ionic 2 RC0、Firebase 3 + AngularFire 2 入门

我无法编译并收到此错误:

rollup:强烈建议不要使用 ofeval(在 c:\XXX\node_modules\angularfire2\node_modules\firebase\firebase.js 中),因为它会带来安全风险,并可能导致缩小问题。 有关更多详细信息,请参阅 https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval

有人知道发生了什么事以及如何解决这个问题吗?

firebase rollupjs ionic2 angularfire2 angular

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

npm 不会安装 Firebase

我正在开发一个 Ionic 应用程序,并希望包含 Firebase。显然,这并不像网页那么容易。所以,我遵循了这个教程。在“设置应用程序”下,它说

\n\n

npm install angularfire2@4.0.0-rc0 firebase --save

\n\n

这给了我输出

\n\n
hacker_news_app_v2@0.0.1 \n/home/sean/Dropbox/Programming/Ionic/hacker_news_app_v2\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 angularfire2@4.0.0-rc0 \n\xe2\x94\x94\xe2\x94\x80\xe2\x94\xac UNMET PEER DEPENDENCY firebase@4.1.2\n  \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 jsonwebtoken@7.4.1 \n  \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ms@2.0.0 \n  \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 safe-buffer@5.1.0 \n\nnpm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 \n(node_modules/chokidar/node_modules/fsevents):\nnpm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for \nfsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: \n{"os":"linux","arch":"x64"})\nnpm WARN angularfire2@4.0.0-rc0 requires a peer of firebase@^3.6.6 but \nnone was installed.\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后我尝试了

\n\n

sudo npm install firebase@4.1.2

\n\n

这给了我

\n\n
hacker_news_app_v2@0.0.1 \n/home/sean/Dropbox/Programming/Ionic/hacker_news_app_v2\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 UNMET PEER DEPENDENCY firebase@4.1.2\n\nnpm WARN …
Run Code Online (Sandbox Code Playgroud)

node.js npm firebase npm-install angularfire2

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

基本的 firestore 安全规则:exists() 工作 - 为什么 get() 不工作?

我正在尝试根据另一个文档验证 firestore 中的读取。

数据结构由 2 个集合组成:“execution”和“test”。

测试集合中只有 1 个文档,其 id 如下:SRJKCxU4HVDBdB3qyfzG,这些值是:

admin true id: "SRJKCxU4HVDBdB3qyfzG" test: 1

我的安全规则如下所示:

service cloud.firestore {
  match /databases/{database}/documents {

    function testFunction(testId) {
      // return exists(/databases/$(database)/documents/test/$(testId));
      return get(/databases/$(database)/documents/test/$(testId)).data.id == "SRJKCxU4HVDBdB3qyfzG";
    }

    match /execution/{exeid} {
      allow read, write: if testFunction("SRJKCxU4HVDBdB3qyfzG");
    }

  }
}
Run Code Online (Sandbox Code Playgroud)

如果我使用return exists(/databases/$(database)/documents/test/$(testId));一切都按预期工作。但无论如何我都无法让这条线工作return get(/databases/$(database)/documents/test/$(testId)).data.id == "SRJKCxU4HVDBdB3qyfzG"

我真的希望我错过了简单而明显的事情?任何帮助都是很常见的。如果需要的话,我还创建了一个演示 firebase 项目和 stackblitz。

谢谢您的帮助。

更新 - 临时解决方案 由于 firestore 安全规则错误,数据属性未填充。这将得到修复。get() 工作的临时解决方案如下:

get(path).data.prop || get(path).prop

firebase firebase-security angularfire2 google-cloud-firestore

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

带有 firestore 的 Angularfire2:从文档中删除特定字段

正如 web 官方文档中提到的:

要从文档中删除特定字段,请在更新文档时使用 FieldValue.delete() 方法:

var cityRef = db.collection('cities').doc('BJ');

// Remove the 'capital' field from the document
var removeCapital = cityRef.update({
    capital: firebase.firestore.FieldValue.delete()
});
Run Code Online (Sandbox Code Playgroud)

我找不到实际使用 angularfire2 (5.0.0-rc.3) 的方法

constructor(private firestore: AngularFirestore) {}

[...]

const cityRef = this.firestore.doc(`cities/BJ`);
cityRef.update({
  capital: this.firestore.FieldValue.delete()
});
Run Code Online (Sandbox Code Playgroud)

无法读取未定义的属性“删除”

firebase angularfire2 angular google-cloud-firestore

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

Firebase 检索数据并作为类型数组返回 - 我的解决方案

我最近开始将我的 iOS 应用程序也转变为网络应用程序。我不知道这个实现是否正确。它有效,但如果有人可以请告诉我它是否正确。

这是我的 LicenseService 中的函数:

get retriveLicences():Licence[] {

const licences: Licence[] = [];

this.afDatabase.list(this.basePath).valueChanges().subscribe((snapshot) => {
  snapshot.forEach(element => {

    const licenceObject = <any>element

    licences.push(
      new Licence(
        licenceObject.name, 
        licenceObject.logoUrl, 
        licenceObject.maxUsers, 
        licenceObject.currentUserCount, 
        licenceObject.startDate, 
        licenceObject.endDate
      )
    );
  });
});

return licences
}
Run Code Online (Sandbox Code Playgroud)

typescript angularfire firebase-realtime-database angularfire2 angular

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

类型“PromiseLike&lt;any&gt;”上不存在属性“catch”

我有以下代码:

this.afDb.list('/demo').push({a: 'b'})
    .then(_ => console.log('works'))
    .catch(err => console.log('err: ', err));
Run Code Online (Sandbox Code Playgroud)

我在“捕获”上收到以下错误:

[ts] Property 'catch' does not exist on type 'PromiseLike<any>'.
Run Code Online (Sandbox Code Playgroud)

看起来像一个 AngularFire2 错误?

javascript firebase firebase-realtime-database angularfire2

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

更新 .snapshotChanges() 代码以使用 angularfire2 5.0..0 rc-8、firebase 5.0.2

我已成功更新 angularfire 5.0.0.rc 8 和 firebase 5.0.2,没有错误模块。我想我要做的最后一件事是更改此代码以检索所有数据

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { IonicPage } from 'ionic-angular/navigation/ionic-page';
import { Observable } from 'rxjs';
import 'rxjs/add/operator/map';
import { Note } from '../../model/note/note.model';
import { NoteListService } from '../../services/note-list.service';

@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  noteList: Observable<Note[]>

  constructor(public navCtrl: NavController, private noteListService: NoteListService) {
    this.noteList = this.noteListService.getNoteList()
      .snapshotChanges()
      .map(
        changes => {
          return changes.map(c => ({
            key: c.payload.key, ...c.payload.val() …
Run Code Online (Sandbox Code Playgroud)

firebase angularfire2 ionic3 angular

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

在 AngularFire2 中使用 DownloadURL 删除文件

使用 AngularFire2 5.0.0-rc.6 和 Angular 5.2.11 ,有没有办法使用 downloadURL 从 Firebase 存储文件夹中删除文件?

angularfire2 angular

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

如何获取 Firebase 实时数据库中添加的最后一项?

我正在使用 Firebase 的实时数据库来实时更新图表内的值。但是,我不知道如何仅检索添加到数据库的最后一个值。

我在limitToLast 和 'child_added' do not work Together #1773中找到了一些解释,但我没有设法让它工作。

到目前为止,我设法做到了这一点:

this.items = db.list('/items').valueChanges()
this.items.forEach(item => {
  this.data = item;
  this.add(this.data[this.data.length-1])
  console.log(this.data)
})

add(point: any) {
   this.chart.addPoint(point)
}
Run Code Online (Sandbox Code Playgroud)

但我知道这根本没有效率。

firebase typescript firebase-realtime-database angularfire2 angular

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

是否可以从 ValueChanges 交换到 (blur) 以提出请求?

我问这个是因为我开始学习一些基本的角度课程,并且我正在使用一些过滤器,在我使用 ValueChanges 输入时将请求发送到 firebase:

这是用于搜索的输入:

<input
  type="search"
  placeholder="Teclee un proveedor..."
  [formControl]="campoBusqueda"
  />
Run Code Online (Sandbox Code Playgroud)

这是我必须使用的代码ngOnInit()

this.campoBusqueda = new FormControl();
this.campoBusqueda.valueChanges.subscribe(term => {
  this.busqueda = term;
  this.cargando = true;
  if (this.busqueda.length !== 0) {
    this.proveedoresService
      .getProveedoresSearch(this.busqueda)
      .subscribe(proveedores => {
        this.proveedores = [];
        // tslint:disable-next-line: forin
        for (const id$ in proveedores) {
          const p = proveedores[id$];
          p.id$ = id$;
          this.proveedores.push(proveedores[id$]);
        }
        if (this.proveedores.length < 1 && this.busqueda.length >= 1) {
          this.noresultados = true;
          this.proveedoresService
            .getProveedores()
            .subscribe( proveedores => {
              this.proveedores = []; …
Run Code Online (Sandbox Code Playgroud)

firebase angularfire2 angular

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