使用事务使用实时数据库触发器递增计数器是否可以接受?
exports.incPostCount = functions.database.ref('/threadsMeta/{threadId}/posts')
.onWrite(event => {
admin.database().ref('/analytics/postCount')
.transaction(count => {
if (count === null) {
return count = 1
} else {
return count + 1
}
})
});
Run Code Online (Sandbox Code Playgroud) javascript node.js firebase firebase-realtime-database google-cloud-functions
我遇到的空值字段的问题与我的数据库中不存在的键有关,所以这里的大部分话语都不适用于你的问题.如果您正在寻找一种在AngularFire2中"加入"查询的方法,下面接受的答案可以很好地解决这个问题.我正在使用combineLatest而不是forkJoin.为了做到这一点,你必须这样做import 'rxjs/add/observable/combineLatest';.
我有以下非规范化的Firebase结构:
members
-memberid1
-threads
-threadid1: true,
-threadid3: true
-username: "Adam"
...
threads
-threadid1
-author: memberid3
-quality: 67
-participants
-memberid2: true,
-memberid3: true
...
Run Code Online (Sandbox Code Playgroud)
我想username在我的threads视图中渲染,它按照排序quality.
我的服务:
getUsername(memberKey: string) {
return this.af.database.object('/members/' + memberKey + '/username')
}
getFeaturedThreads(): FirebaseListObservable<any[]> {
return this.af.database.list('/threads', {
query: {
orderByChild: 'quality',
endAt: 10
}
});
}
Run Code Online (Sandbox Code Playgroud)
我的组件:
ngOnInit() {
this.threads = this.featuredThreadsService.getFeaturedThreads()
this.threads.subscribe(
allThreads =>
allThreads.forEach(thisThread => {
thisThread.username = this.featuredThreadsService.getUsername(thisThread.author) …Run Code Online (Sandbox Code Playgroud) firebase typescript firebase-realtime-database angularfire2 angular
我正在尝试构建我的Angular 5应用程序,我收到错误:
无法在/home/brightwater/Differ/src/app/thread-lists/thread-lists.component.ts中确定类ThreadListTabsComponent的模块!将ThreadListTabsComponent添加到NgModule以修复它.
这很令人困惑,因为我在模块中导入有问题的组件:
thread-lists.module.ts:
import { OtherModules } from './modules-everywhere';
import { NgModule } from '@angular/core'
import { SomeOtherComponents } from './other-components.component';
import { ThreadListTabsComponent } from './thread-list-tabs.component';
@NgModule({
imports:
[
OtherModules
],
declarations: [
OtherComponents,
ThreadListTabsComponent
],
exports: [
OtherComponents,
ThreadListTabsComponent
],
providers: [ ThreadListsService ]
})
export class ThreadListsModule { }
Run Code Online (Sandbox Code Playgroud)
这是组件:
线程列表tabs.component.ts
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Router } from '@angular/router';
import { ThreadListsService } from …Run Code Online (Sandbox Code Playgroud) 我想使用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实时数据库,这样当我向它提交内容时,它会立即在视图中呈现,而不需要jQuery或ajax.
我想为这些元素的渲染设置动画,这样当一个新元素被添加到DOM时,它div的background-color绿色就会变成绿色并逐渐消失.我不想要的是div这个类的所有人在加载时执行这个动画.
我知道如何做前者:
@keyframes green-fade {
0% {background: rgb(173, 235, 173);}
100% {background: none;}
}
.post-div {
animation: green-fade 5s ease-in 1;
}
Run Code Online (Sandbox Code Playgroud)
但是当然这个动画会在渲染时发生,包括加载时.
我对"Angular 2 way"感兴趣.
我试图Object.values()在我的一个Firebase云功能中使用,但它不被识别为功能.我认为这意味着在Firebase云功能上不能使用es7功能.我的问题是双重的:
首先,这是真的吗?其次,我认识到某些浏览器不支持该功能,但我想知道这对Firebase云功能是否重要.任何人都可以向我解释这个吗?
我正在编写一个单字段表单,希望Enter键将表单前进到下一个输入字段。由于页面上还有另一种形式,当该表单中的输入之一是时,我只希望按Enter键可以使该表单前进activeElement。
我已经在这里完成了一个极其冗长的if()声明:
document.addEventListener( 'keydown', function( ev ) {
var keyCode = ev.keyCode || ev.which;
var ids = [ 'this', 'that', 'there', 'thing', 'other' ];
if ( document.getElementById( ids[0] ) === document.activeElement || document.getElementById( ids[1] ) === document.activeElement || document.getElementById( ids[2] ) === document.activeElement || document.getElementById( ids[3] ) === document.activeElement || document.getElementById( ids[4] ) === document.activeElement) {
if( keyCode === 13 ) {
ev.preventDefault();
self._nextQuestion();
}
}
} );
Run Code Online (Sandbox Code Playgroud)
每个输入都属于同一类:.questions。我已经尝试过类似的东西:
document.addEventListener( 'keydown', function( ev ) …Run Code Online (Sandbox Code Playgroud) 今天我更新到AngularFire2版本4.我正在努力使用电子邮件和密码登录.在我使用以下内容之前:
login() {
this.af.auth.login({
email: this.email,
password: this.password,
},
{
provider: AuthProviders.Password,
method: AuthMethods.Password,
}).catch(function(error) {
// Error
})
}
Run Code Online (Sandbox Code Playgroud)
似乎登录不是新方法Auth.这似乎是替代品singInWithEmailAndPassword().我试过这个:
login() {
this.afAuth.auth.signInWithEmailAndPassword({
email: this.email,
password: this.password,
},
{
provider: AuthProviders.Password,
method: AuthMethods.Password,
}).catch(function(error) {
// Error
})
}
Run Code Online (Sandbox Code Playgroud)
它显然与呼叫签名不匹配,即:
signInWithEmailAndPassword(email: string, password: string): firebase.Promise<any>
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么做.
我需要一个类的名字,EventTarget我得到这样的:
<div class="orig-post" (mousemove)="onMouseMove($event)"></div>
onMouseMove(event: MouseEvent): void {
this.target = event.target
console.log(this.target) // Outputs the element the mouse is currently over
}
Run Code Online (Sandbox Code Playgroud)
我希望能够将变量分配给作为目标的元素的类名.如果我使用的东西就像getSelection()我可以做的那样selection.anchorNode.parentElement.className.有没有办法在纯JavaScript中执行此操作?我正在使用Angular 2,并希望完全避免使用jQuery.
angular ×6
firebase ×5
javascript ×5
angularfire2 ×4
typescript ×3
angular-cli ×1
animation ×1
css ×1
dom ×1
node.js ×1
tsconfig ×1