我目前正在使用Angular 2和angularFire2进行项目.我的数据库在Firebase中看起来像这样:base:/ data
[{Name:test1},
{Name:test2},
{Name:test3}]
Run Code Online (Sandbox Code Playgroud)
所有商品都有Firebase密钥.
现在我试图用RX中的Observabels从Firebase中获取数据.当我这样做时,我在控制台中获取名称:
let items= af.database.list('/data').map(i=>{return i});
items.forEach(i=>i.forEach(e=>(console.log(e.name))));
Run Code Online (Sandbox Code Playgroud)
输出:test1,test2,test3.一切正常.
但是当我这样做时:
console.log(items.first());
Run Code Online (Sandbox Code Playgroud)
我得到一个FirebaseListObservable.
如何才能从FirebaseListObservable中获取第一个对象?如何编辑列表中的项目?喜欢:
items[0].name=test3
Run Code Online (Sandbox Code Playgroud)
如何从项目中获取Firebase密钥
我如何从列表中的项目获取firebaseKey?
rxjs firebase firebase-realtime-database angularfire2 angular
我正在使用AngularFire2(2.0.0-beta.2)与angular2(2.0.0-rc.4)组合.我想从Angularfire2访问本机firebase对象(不是AngularFire根对象).
在我的组件中,我想进行如下调用:
firebase.auth().currentUser.updateEmail("user@example.com")
Run Code Online (Sandbox Code Playgroud)
firebase是本机firebase对象,就像你从下面的片段得到的那样:
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase.js"></script>
<script>
// Initialize Firebase
// TODO: Replace with your project's customized code snippet
var config = {
apiKey: "apiKey",
authDomain: "projectId.firebaseapp.com",
databaseURL: "https://databaseName.firebaseio.com",
storageBucket: "bucket.appspot.com",
};
firebase.initializeApp(config);
</script>
Run Code Online (Sandbox Code Playgroud)
但我不明白如何设置我的angular2组件,以便firebase对象在其中可见.可能是一个非常简单的问题需要解决,但我不知道如何解决 - 我不是一个有角度的专家.我希望有和AngularFire api得到对象,但没有.
此外,我试图这样做的原因是我不认为angularfire2 api是完整的(这可以理解,因为它仍处于测试版)并且我正在努力解决这个问题.例如,我想更新用户的电子邮件地址或密码,或向他们发送忘记密码的电子邮件.AngularFire2中似乎还没有这个功能,所以我尝试使用本机Firebase对象来实现.
我正在尝试使用AngularFire 2(2.0.0-beta.2)将输入元素三路绑定到Angular.js 2(2.0.0-rc.4)中的firebase数据库.
我有一个非常简单的HTML:
<form (ngSubmit)="onSubmit()" #commentForm="ngForm">
<input [(ngModel)]="model.author" type="input" name="author" required>
</form>
Run Code Online (Sandbox Code Playgroud)
在我的组件中,为了保存和检索此输入的内容到firebase,我有一个这样的实现:
export class CommentFormComponent implements OnInit, AfterViewInit {
@ViewChild("commentForm") form;
// http://stackoverflow.com/questions/34615425/how-to-watch-for-form-changes-in-angular-2
firebaseInitComplete = false;
model: Comment = new Comment("", "");
firebaseForm: FirebaseObjectObservable<Comment>;
constructor(private af: AngularFire) { }
ngAfterViewInit() {
this.form.control.valueChanges
.subscribe(values => {
// If we haven't get the initial value from firebase yet,
// values will be empty strings. And we don't want to overwrite
// real firebase value with empty string on page load …Run Code Online (Sandbox Code Playgroud) 无法解决此问题:
app.component.ts
import { AngularFire, AuthProviders, AuthMethods } from 'angularfire2';
/angularfire2/index has no exported member 'AngularFire',
/angularfire2/index has no exported member 'AuthProviders',
/angularfire2/index has no exported member 'AuthMethods '
Run Code Online (Sandbox Code Playgroud)
但是在app.module.ts中
import { AngularFireModule } from 'angularfire2';
Run Code Online (Sandbox Code Playgroud)
工作正常,我可以初始化应用程序
的package.json
"angularfire2": "^4.0.0-rc.0",
"core-js": "^2.4.1",
"firebase": "^3.9.0",
...
"devDependencies": {...
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
Run Code Online (Sandbox Code Playgroud) 我在Ionic2学习angularfire2
const newUser = this._db.list('/users');
setTimeout(() => {
newUser.push(this.userInfo)
.then((data) => console.log(data))
},3000)
Run Code Online (Sandbox Code Playgroud)
我想知道在推送新数据时是否可以设置自定义密钥.我在互联网上尝试了各种建议,在插入后更新密钥,但没有成功.
我正在使用angular和firebase进行应用程序.我按照现场给出的说明安装了firebase,版本如下,
"angularfire2": "^5.0.0-rc.4",
"firebase": "^4.8.1",
Run Code Online (Sandbox Code Playgroud)
但是出现以下错误
node_modules/@firebase/database/dist/esm/src/api/Database.d.ts(4,33)中的错误:错误TS2307:找不到模块'@ firebase/app-types/private'.node_modules/@firebase/database/dist/esm/src/core/AuthTokenProvider.d.ts(1733):错误TS2307:找不到模块'@ firebase/app-types/private'.
我正在尝试将文档插入集合中。我希望文档具有reference要插入到集合中的类型的属性。但是每次我插入到集合中时,它都会以字符串或对象的形式出现。如何以编程方式插入reference类型化的值?
绝对有可能在用户界面中做到这一点:
我想将来自customers表的init数据加入到项目列表中.
模型是这样的:
项目
顾客
你有一个例子,我如何使用angularfire2从angular2组件做到这一点?
我的控制器看起来像这样:
import { Component, OnInit } from '@angular/core';
import { Project } from '../project';
import { Router } from '@angular/router';
import { FirebaseAuth } from 'angularfire2';
import { AngularFire, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';
import { Observable } from 'rxjs';
@Component({
moduleId: module.id,
selector: 'app-projects',
templateUrl: 'projects.component.html',
styleUrls: ['projects.component.css']
})
export class ProjectsComponent implements OnInit {
projects: FirebaseListObservable<any[]>;
customers: FirebaseListObservable<any[]>;
projectName: string;
constructor(
private router: Router,
private af: AngularFire
) …Run Code Online (Sandbox Code Playgroud) 最近AngularFire如何处理对象/列表以及引用整个应用程序中的对象,我们遇到了一些严重的问题.
主要的是旧的AngularFireObject & AngularFireList工作与新的相比.我们的应用程序高度依赖于$key价值,因为我们非常规范化(如推荐).
现在,文档使用一个map示例来获取$key值,但是它的工作方式不一样,甚至valueChanges()看起来效果也不一样.
我不完全确定我们现在应该做些什么改变.
/* /items/
a/{name: 'Dennis', city: 'Dallas'}
b/{name: 'Katie', city: 'Austin'}
c/{name: 'Will', city: 'Chicago'}
*/
let myAfList = this.af.list('path/to/items');
let itemsFirst, itemsSecond, itemsThird;
myAfList.subscribe(items => itemsFirst = items);
setTimeout(_ => myAfList.subscribe(items => itemsSecond = items), 1000);
setTimeout(_ => myAfList.subscribe(items => itemsThird = items), 2000);
/* Results for all three item arrays
itemsFirst: [
{name: 'Dennis', city: 'Dallas', $key: 'a'},
{name: 'Katie', city: 'Austin', $key: …Run Code Online (Sandbox Code Playgroud) 给定一个给定的Firestore路径,检查该记录是否存在或者没有创建可观察文档并订阅它的最简单,最优雅的方法是什么?
angularfire2 ×10
firebase ×9
angular ×5
javascript ×2
rxjs ×2
angular-cli ×1
angularfire ×1
angularjs ×1
import ×1
npm ×1