我能够使firebaseSimpleLogin工作并将当前用户存储在rootScope中.当我转到另一个页面并返回到feed页面时,所有内容都会加载,但是当我刷新$ rootScope.currentUser时为null.其他人遇到过这个问题吗?
我的app.run函数中有这段代码:
$rootScope.$on('$firebaseSimpleLogin:login',function(e, auth){
$rootScope.currentUser = User.find(auth.id);
});
Run Code Online (Sandbox Code Playgroud)
这是我的FeedCtrl试图加载用户的帖子
app.controller('FeedCtrl',['$scope', '$rootScope','User','Auth','Post',function($scope, $rootScope,User,Auth,Post){
populateFeed();
console.log($rootScope.currentUser);
$scope.logout = function(){
Auth.logout();
};
$scope.savePost = function(){
Post.create($scope.post).then(function(post){
$scope.post.text = "";
});
};
function populateFeed(){
$scope.posts = {};
angular.forEach($rootScope.currentUser.posts,function(id){
$scope.posts[id] = Post.find(id);
});
}
}]);
Run Code Online (Sandbox Code Playgroud)
我的主要应用模块
var app = angular.module('myapp',['ui.router','firebase']);
app.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('/',{
url: '/',
controller: 'MainCtrl',
templateUrl: 'views/index.html'
})
.state('feed',{
url: '/feed',
controller: 'FeedCtrl',
templateUrl: 'views/feed.html',
authenticate: true
})
.state('login',{
url: '/login',
controller: 'LoginCtrl',
templateUrl: 'views/login.html'
})
.state('signup',{
url: '/signup',
controller: 'LoginCtrl', …Run Code Online (Sandbox Code Playgroud) Firebase的ping服务使用的是Google Chrome浏览器报告的同步XMLHttpRequest,如下所示:
主线程上的同步XMLHttpRequest因其对最终用户体验的不利影响而被弃用.如需更多帮助,请访问http://xhr.spec.whatwg.org/.
这个问题的根源来自:
.lp?dframe=t&id=612050&pw=gcdpSrzjvk&ns=myapp:5
Run Code Online (Sandbox Code Playgroud)
它是Firebase中的一个错误吗?这暂时没有引起任何问题.但是将来,浏览器可能会弃用同步XHR.
我发现使用AngularFireAuthModulefrom '@angular/fire/auth';会导致内存泄漏,导致 20 小时后浏览器崩溃。
版本:
我使用今天更新的最新版本,对所有软件包使用 ncu -u。
角火: "@angular/fire": "^5.2.3",
Firebase 版本: "firebase": "^7.5.0",
如何重现:
我在StackBliztz 编辑器上做了一个最小的可重现代码
这里是直接测试bug的链接StackBlizt test
症状:
您可以自己检查代码是否没有任何作用。它只是打印 hello world。但是,Angular App 使用的 JavaScript 内存增加了11 kb/s(Chrome 任务管理器 CRTL+ESC)。打开浏览器 10 小时后,使用的内存达到约800 mb(内存占用量约为1.6 Gb 的两倍!)
结果,浏览器内存不足,chrome 选项卡崩溃。
在性能选项卡下使用chrome的内存分析进一步调查后,我清楚地注意到侦听器的数量每秒增加2个,因此JS堆相应增加。
导致内存泄漏的代码:
我发现使用该AngularFireAuthModule 模块会导致内存泄漏,无论是在component构造函数中还是在service.
import { Component } from '@angular/core';
import {AngularFireAuth} from '@angular/fire/auth';
import {AngularFirestore} from '@angular/fire/firestore';
@Component({
selector: 'app-root',
templateUrl: …Run Code Online (Sandbox Code Playgroud) 我可以使用以下内容将对象添加到Firebase数据存储中:
var uniqueId = {
name: "a name",
location: "new york"
}
$scope.myItems.$add(uniqueId).then(function(firebaseId){
// do something on success
}, function(){
// do something if call fails
});
Run Code Online (Sandbox Code Playgroud)
以上将在我的数据存储中添加一个对象,如果添加成功,则返回Firebase生成的ID.我刚刚添加的对象保存在此键下.
有没有办法让我在添加到数据存储时指定键名是什么?
我有一个使用 AngularFire 构建并托管在 Firebase 上的 Angular 应用程序。我应该如何使用 Analytics SDK 来设置用户 ID、跟踪页面加载和记录自定义事件?
google-analytics firebase angularfire google-analytics-firebase angular
我在表单上使用ng-submit将数据推送到Firebase,一切都按预期工作.我想做的是同时改变观点.在提交按钮本身我有ng-click设置来使用$ location执行一个函数.如果我将changeView函数放在.controller方法中,我就无法使用$ location(具体来说,它说 - "错误:'undefined'不是一个对象(评估'$ location.path')").任何帮助都是超级的.
// This doesn't work and throws the error
myApp.controller('CtrlName', ['$scope', 'angularFireCollection',
function($scope, angularFireCollection, $location) {
$scope.changeView = function(view) {
$location.path(view);
}
}
]);
// This works as expected, but I'm name spacing my functions globally and I will have to change how I'm accessing my Firebase, which isn't really desired.
function CtrlName($scope, angularFireCollection, $location) {
$scope.changeView = function(view) {
$location.path(view);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的模板:
<form role="form" ng-submit="tactics.add(tactic)">
<div class="form-group">
<label>Select Method</label>
<select class="form-control" ng-model="tactic.type">
<option>Email</option> …Run Code Online (Sandbox Code Playgroud) 我在这里阅读了指南:https://angular.io/docs/ts/latest/guide/router.html
看起来非常简单,但是,我不确定如何在auth guard(canActivate)中使用angularfire2的身份验证.我试过的是:
AuthService
import { Injectable } from '@angular/core';
import { AngularFire } from 'angularfire2';
@Injectable()
export class AuthService {
private user: any;
constructor(private af: AngularFire) {
this.af.auth.subscribe(user => {
this.user = user;
})
}
get authenticated(): boolean {
return this.user ? true : false;
}
}
Run Code Online (Sandbox Code Playgroud)
AuthGuard
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private router: Router, private authService: AuthService) { }
canActivate(): Observable<boolean> | boolean {
if (this.authService.authenticated)
return true;
this.router.navigate(['/login']);
return …Run Code Online (Sandbox Code Playgroud) 注意:我想我能够重现这个(参见stackblitz 示例)。错误在控制台中打印为“
INTERNAL ASSERTION FAILED: Expected a class definition”。这与我在本地得到的不同,但对我来说这看起来是同一个问题。不管怎样,只需注释掉第 15 行
app.component.ts,错误就会消失。
我正在尝试开始使用 Firebase,但是当我安装和编译 Angular 项目时,出现以下错误:
Module not found: Error: Package path ./compat is not exported from package /home/sfalk/workspaces/web-mobile/node_modules/firebase (see exports field in /home/sfalk/workspaces/web-mobile/node_modules/firebase/package.json)
有趣的是,当我AuthService像这样注入我的eg时,我只会收到此错误:
import {Component, OnInit} from '@angular/core';
import {FormBuilder} from '@angular/forms';
import {AuthService} from "../../../services/auth.service";
@Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.scss']
})
export class RegisterComponent implements OnInit {
public loading = false;
constructor(
private formBuilder: FormBuilder,
public …Run Code Online (Sandbox Code Playgroud) 我有一个ionic2应用程序,并使用Firebase和angularFire2.我想使用angularFire2从firebase获取当前的身份验证状态和当前的auth对象/用户.
这是迄今为止的工作 - 我可以对用户进行身份验证并订阅FirebaseAuthState以获取facebook用户对象.
constructor(platform: Platform, private auth: FirebaseAuth) {
auth.subscribe((user: FirebaseAuthState) => {
if (user) {
// I could store user in localstorage, but I'd like to see an All Firebase solution
this.rootPage = TabsPage;
} else {
this.rootPage = LoginPage;
}
});
Run Code Online (Sandbox Code Playgroud)
现在我可以在这里设置localstorage并缓存我的用户对象以记住身份验证状态.但是,我很想知道如何在没有实现自己的自定义本地存储密钥的情况下才能使用Firebase.我看到Firebase存储了它自己的localStorage密钥,因此知道它已登录.
如何从代码中获取auth对象?另外,我尝试在AngularFire2文档中列出的示例来渲染模板中的auth状态 - 但这给了我一个错误.
import {FirebaseAuth} from 'angularfire2';
@Component({
selector: 'auth-status',
template: `
<div *ng-if="auth | async">You are logged in</div>
<div *ng-if="!(auth | async)">Please log in</div>
`
})
class App {
constructor (@Inject(FirebaseAuth) public auth: FirebaseAuth) …Run Code Online (Sandbox Code Playgroud) 我使用匿名身份验证允许我的用户无需登录即可使用该应用.但是,Firebase似乎无限期地保留这些匿名用户ID.有没有办法自动清除这些或设置某种过期规则?我不希望这些一次性使用ID永远存在,并使来自提供商的实际用户数据混乱.