我想制作一个war文件来在apache tomcat服务器中部署angular2项目。我做了一个 Maven 项目并在其中插入了 angular2 项目。然后我使用angular-cli在maven项目的src/main中创建了webapp文件夹(而不是angular2项目中的dist文件夹)。当我运行 apache 服务器时,它显示以下错误。
从http://localhost:8080/app/app.module.js加载http://localhost:8080/vendor/angularfire2/angularfire2.js为“angularfire2”时出错;区域: ; 任务: Promise.then ;值:错误:错误:XHR 错误(404 未找到)正在加载http://localhost:8080/traceur (...) null
这看起来麻烦的依赖是angularfire2。怎么算我们的?顺便说一句,我使用 angular2 rc-5。
我想知道是否可以在查询列表中使用"child_added"事件.像这样:
this.curUserPosts = this.af.database.list('/posts', {
query: {
orderByChild: 'user/id',
equalTo: id
}
}).$ref.on("child_added", (child) => {
console.log(child);
});
Run Code Online (Sandbox Code Playgroud)
我对以下内容感兴趣:它会起作用吗?仅当添加的子对应于查询时才会正常触发.性能如何.
而且,在firebase中处理这些查询列表的首选方法是什么?
rxjs firebase firebase-realtime-database angularfire2 angular
我遇到的空值字段的问题与我的数据库中不存在的键有关,所以这里的大部分话语都不适用于你的问题.如果您正在寻找一种在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
我正在尝试使用 firebase 的 AngularFire2 进行 Facebook 身份验证。我遵循与本教程完全相同的步骤github.com/angular/angularfire2/blob/master/docs/Auth-with-Ionic2.md
但由于某种原因,这行不通。它给了我提供者页面上的许多错误。这是我的代码。
import { Injectable } from '@angular/core';
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
@Injectable()
export class AuthService {
private authState: Observable<firebase.User>;
private currentUser: firebase.User;
constructor(public http: Http, public afAuth: AngularFireAuth) {
console.log('Hello AuthService Provider');
this.authState = afAuth.authState; //First error here.
afAuth.subscribe((user: firebase.User) => { //second here …Run Code Online (Sandbox Code Playgroud) angularjs firebase firebase-authentication ionic2 angularfire2
下面的代码片段是我的 ionic3/angularfire2 项目的一部分。它连接到 Firestore 数据库 - 并应返回文档的可观察快照。
从我的网络研究中,我可以看到其他人使用了类似的语法 - 我找不到我的解决方案
// (all other imports are fine)
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
Run Code Online (Sandbox Code Playgroud)
在构造函数中,我注入...
private db: AngularFirestore
Run Code Online (Sandbox Code Playgroud)
下面的代码有错误(我很不高兴)
// customerRef: AngularFirestoreDocument<Customer>;
this.customerRef = this.db.doc(`customers/${k}`);
// cust: Observable<Customer>;
this.cust = this.customerRef.snapshotChanges().map(actions => {
return actions.map(action => {
const data = action.payload.doc.data() as Customer;
const id = action.payload.doc.id;
console.log('>>>>', { id, ...data });
return { id, ...data };
});
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
Typescript Error
Property 'map' does not exist on type 'Action<DocumentSnapshot>'. …Run Code Online (Sandbox Code Playgroud) 我正在使用 Angularfire2。假设我有一个users和comments集合。添加评论时,引用创建评论的用户的正确方法是什么?起初我以为我可以简单地创建一个具有如下结构的评论:
{
message: string,
user: {
uid: string,
username: string,
...
}
}
Run Code Online (Sandbox Code Playgroud)
但问题是,如果用户更新他的个人资料,那么这里的数据就会不正确。是否可以在创建评论时简单地提供用户的 id,并在查询评论时获取整个用户的数据?
要允许访问管理路由,我必须检查两件事:
管理卫士
import {ActivatedRouteSnapshot, CanActivate, Router,
RouterStateSnapshot} from '@angular/router';
import {Observable} from 'rxjs/Observable';
import {AngularFireAuth} from 'angularfire2/auth';
import {Injectable} from '@angular/core';
import {DbActionsService} from '../services/db-actions.service';
import {AuthService} from '../services/auth.service';
import 'rxjs/add/operator/map';
@Injectable()
export class AdminGuard implements CanActivate {
constructor(private afAuth: AngularFireAuth, private router: Router, private dbAction: DbActionsService, private authService : AuthService) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
if (this.afAuth.auth.currentUser) {
return this.dbAction.getUserProfileData(this.afAuth.auth.currentUser.email).map((user) => {
if (user[0].admin) {
return true;
} else {
this.router.navigate(['/']); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Angular Fire 包访问 Angular 环境中可调用函数的错误消息。请看下面的代码:
角度(客户端)
async myCallableFunction(id: string) {
try {
const res = await this.afFunctions.httpsCallable('callableFunction')({
id
}).toPromise();
console.log(res);
} catch (err) {
console.error('Error is:', err);
}
}
Run Code Online (Sandbox Code Playgroud)
服务器端(Firebase 功能)
exports.callableFunction = functions.https.onCall((data: {
id: string
}, context: https.CallableContext) => {
// throw error for testing only
throw new https.HttpsError('unknown', 'Test Error Message');
});
Run Code Online (Sandbox Code Playgroud)
控制台记录的错误消息是:
[console.error]:“错误是:”{“代码”:“未知”,“行”:100205,“列”:32,“sourceURL”:“ http://192.168.1.100:8100/vendor.js ” }
如何从 Cloud Firestore 的响应中访问错误消息?
提前致谢。
error-handling typescript angularfire google-cloud-functions angularfire2
我有一个向用户展示艺术作品的提要。我想按用户发布帖子的类别和时间过滤用户帖子,以便该提要的最新帖子更接近页面顶部。我正在使用 firebase 函数来检索此数据。
我有一个 firestore 集合,看起来像这样
tasks -tasksID-
{
category: art
date: 16 october at 3:00pm
images: {
0 image1
1 image2
}
}
Run Code Online (Sandbox Code Playgroud)
火力基地功能:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin'
admin.initializeApp()
export const getFeed = functions.https.onCall(async (req,res) =>{
const docs = await admin.firestore().collection('tasks').where('category',
'==', 'art').orderBy('date', 'desc').limit(20).get()
return docs.docs.map(doc => {
return {
postID: doc.id,
...doc.data()
}
})
})
Run Code Online (Sandbox Code Playgroud)
艺术提要打字稿:
artFeed (){
const getFeed = this.aff.httpsCallable('getFeed')
this.ajax = getFeed({}).subscribe(data=> {
console.log(data)
this.posts = data …Run Code Online (Sandbox Code Playgroud) firebase typescript google-cloud-platform google-cloud-functions angularfire2
我有一个受身份感知代理(IAP)保护的角度应用程序。我正在尝试将 Firebase 添加到此应用程序,以便将 firestore 用于使用 AngularFire 的组件。我不想让用户登录两次,所以我考虑使用 IAP 与 Firebase 进行身份验证。
我试过了:
让 GCP 发挥其魔力,看看用户是否自动插入 Firebase Auth 模块 - 但事实并非如此。
我尝试在 cookie 中使用从 IAP 获得的令牌,方法GCP_IAAP_AUTH_TOKEN是signInWithCustomToken- 不起作用,令牌无效。
我尝试过getRedirectResult在通过 IAP 登录后使用它是否已注入那里 - 但事实并非如此。
我花了几天时间试图让它发挥作用,我也让一位同事看过它,但这似乎不可能。现在,作为最后的手段,我在这里写信看看是否有人知道这是否可能。
如果没有,我将不得不建议团队切换身份验证方法并摆脱 IAP,但我宁愿保留它。
更多信息:
环境: App Engine Flex 上的 NodeJS 10
角度版本: 7.xx
AngularFire 版本: 5.2.3
注意:我没有后端,因为我想独立使用这个组件,如果需要的话最多可以与几个云功能一起使用。我正在尝试使用 Firestore 作为“后端”。
google-app-engine firebase google-cloud-platform angularfire2 google-iap
angularfire2 ×10
firebase ×8
angular ×6
typescript ×3
angular5 ×1
angularfire ×1
angularjs ×1
dictionary ×1
google-iap ×1
ionic2 ×1
maven ×1
rxjs ×1