我正在使用AngularFire2.这就是我接近我的AuthGuard服务的方式:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
this.af.auth.subscribe((auth) => {
if(auth == null) {
this.router.navigate(['/login']);
this.allowed = false;
} else {
this.allowed = true;
}
})
return this.allowed;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码有效,除非我直接访问受保护的页面(我在浏览器中输入URL),它在订阅解析为true后不会加载相应的组件.
在角度1中,保护路线是确保在路线加载之前先解决某些事情.
它出现在角度2中,路由加载(无论是真还是假,并且不等待来自线路的任何响应),因此当订阅值返回为真时,我必须转到另一条路线,然后返回在它工作之前.
什么是保护我的路线在Angular 2中响应的正确方法?
我有一个关于处理Firebase中多对多关系的问题.基本上,我正在尝试从Firebase数据中的多个路径构建用户配置文件对象.我已经尝试构建一个返回observable的函数,然后更新该observable中的数据,因为嵌套的observable从Firebase获取数据.
问题是嵌套的observable永远不会被调用,从我所知道的.几个小时以来,我一直在打我的头,没有任何真正的成功.谁能说出我做错了什么?我觉得这是一个很常见的问题,可以解决.
public getUserProfile(data) {
return this._af.database.object(`/social/users/${data.id}`).map((user) => {
for ( let vidKey in user.videos) {
// Once the code hits this line, it never fires at all :(
this._af.database.object(`/social/videos/${vidKey}`).map((video) => {
user.videos[vidKey] = video;
});
}
return user;
});
}
Run Code Online (Sandbox Code Playgroud) firebase firebase-realtime-database ionic2 angularfire2 angular
今天我更新到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)
我不知道该怎么做.
我正在使用此查询来验证我的Firebase上是否存在数据(使用AngularFire2)
let aux = this.afData.list("/drivers", { query: { orderByChild: '/accountHistory/approved', equalTo: null } });
Run Code Online (Sandbox Code Playgroud)
工作得很好,但我还需要进行反向查询.
像这样
let aux = this.afData.list("/drivers", { query: { orderByChild: '/accountHistory/approved', equalTo: !null } });
Run Code Online (Sandbox Code Playgroud)
问题是.第二个查询,仅在值为TRUE时返回,我在/ driveruid/accountHistory/approved'上存储TIMESTAMP
有什么方法可以只验证Value是否存在?
谢谢!
javascript firebase firebase-realtime-database angularfire2 angular
我需要将一个对象推入节点关注者,但我没有找到方法.
我试试这个:
this.af.database.list(`profile/${user}/followers/`).push({[from]: true});
Run Code Online (Sandbox Code Playgroud)
我需要下一个输出
任何的想法?
在网络应用中,我们使用Firebase Auth来管理登录名和(基本)帐户创建。如果在具有多个Google帐户的活跃用户中使用Google登录选项,则会向用户显示Google帐户选择器,以选择要在我们网站上使用的帐户。其标题如下所示:
选择一个帐户
以继续访问mydomain.com
就我的Web应用而言,它没有显示mydomain.com,而是显示了<firebase-project-id> .firebaseapp.com。
我要做的就是更改,以便帐户选择器弹出窗口显示mydomain.com?
web-applications google-oauth2 firebase-authentication angularfire2
我正在尝试使用firebase来获取分析事件,但我得到的只是session_start事件。我正在使用Firebase 离子插件。
这是我的代码:
constructor(public navCtrl: NavController, private nav: NavController,
private firebaseAnalytics: FirebaseAnalytics) {
this.firebaseAnalytics.setEnabled(true);
this.firebaseAnalytics.logEvent('home_page_viewed', {page: "dashboard"})
.then((res: any) => console.log(res))
.catch((error: any) => console.error(error));
}
Run Code Online (Sandbox Code Playgroud)
因此,我希望在Firebase控制台中看到一个名为“ home_page_viewed”的事件,但我没有看到此事件。我所看到的只是session_start事件。
有人知道我该怎么办?
因此,我正在使用Angular 6使用AngularFire2构建Web应用程序,并且在加载应用程序时出现以下错误:
auth.js:255 Uncaught ReferenceError: global is not defined
at Object../node_modules/firebase/auth.js (auth.js:255)
at __webpack_require__ (bootstrap:81)
at Object../node_modules/firebase/firebase-browser.js (firebase-browser.js:11)
at __webpack_require__ (bootstrap:81)
at Object../src/app/core/auth.service.ts (auth.guard.ts:18)
at __webpack_require__ (bootstrap:81)
at Object../src/app/app.component.ts (main.js:156)
at __webpack_require__ (bootstrap:81)
at Object../src/app/app.module.ts (app.component.ts:9)
at __webpack_require__ (bootstrap:81)
./node_modules/firebase/auth.js @ auth.js:255
__webpack_require__ @ bootstrap:81
./node_modules/firebase/firebase-browser.js @ firebase-browser.js:11
__webpack_require__ @ bootstrap:81
./src/app/core/auth.service.ts @ auth.guard.ts:18
__webpack_require__ @ bootstrap:81
./src/app/app.component.ts @ main.js:156
__webpack_require__ @ bootstrap:81
./src/app/app.module.ts @ app.component.ts:9
__webpack_require__ @ bootstrap:81
./src/main.ts @ environment.ts:15
__webpack_require__ @ bootstrap:81
0 @ main.ts:14
__webpack_require__ @ …Run Code Online (Sandbox Code Playgroud) 我根据rxjs 6文档编写了以下代码。我目前正在运行angular 5,rxjs 6和angularfire2 rc.10。我得到的错误是
[ts] property 'pipe' does not exist on type 'OperatorFunction<{}, [{}, user, string]>'.
Run Code Online (Sandbox Code Playgroud)
这是代码
this.companies$ = combineLatest(this.authService.user$, this.filter$).pipe(
switchMap(([user, filter]) =>
this.afs.collection("companies", ref => {
if (user) {
ref.where("owner.network", "==", user.activeNetworkProfile.id);
}
if (user) {
ref.where("name", "==", filter);
}
return ref;
}).valueChanges()
)
);
Run Code Online (Sandbox Code Playgroud)
this.authService.user $和this.filter $是可观察的。
public filter$: Observable<string>;
public user$ : Observable<User>;
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个依赖Angularfire2的Angular 6项目。我正在使用Firestore和Firebase存储。我已经将我的应用程序转换为通用角度,当我运行server.js该应用程序时,它说正在监听,localhost:4000但是一旦我用localhost:4200终端打开浏览器,就会显示以下错误:
ReferenceError: XMLHttpRequest is not defined
Run Code Online (Sandbox Code Playgroud)
angularfire2 ×10
angular ×7
firebase ×7
angular6 ×1
angularfire ×1
ionic2 ×1
ionic3 ×1
javascript ×1
rxjs ×1
rxjs6 ×1
typescript ×1