我正在开发一个简单的企业 AngularJS 应用程序,并计划在后端使用 Firebase。
我必须支持的浏览器是 IE8 和 Chrome(最新)。
我已经设法修复了前端中所有与 IE 相关的怪癖,并且可以成功地从我的 Firebase 检索数据。由于 IE8 不支持 WebSockets,我假设它使用的是长轮询。(这在性能方面很好,该应用程序非常简单,只需提取/更新两到三个数据)。
矛盾的是,我在 Chrome 中反复看到以下错误,并且无法连接到 Firebase。我假设这是由于公司网络的防火墙/代理。
WebSocket connection to 'wss://xxx.firebaseio.com/.es?v=5' failed: WebSocket is closed before the connection is established.
Run Code Online (Sandbox Code Playgroud)
我无法控制防火墙/代理,所以我的问题是我是否可以强制 Chrome 也使用长轮询,在创建 Firebase 引用时使用某种配置标志?
我混合使用 Angularfire 和直接 Firebase。该应用程序在 IE 中运行良好,因此我的代码似乎没有任何问题。(也是简单的测试脚本遇到同样的问题)
更新:该应用程序在 Chrome 中不起作用(因此是我的问题),所以这可能是我应该使用 Firebase 提出的错误,但无论强制长轮询的方法(大概)都可以解决我的问题。
我陷入了僵局.我正在尝试使用$ firebaseAuth创建一个使用AngularFire的用户,而不是文档中推荐的已弃用的FirebaseSimpleLogin.我确信表单提交了有效的电子邮件和密码,但我仍然在控制台中收到以下错误:
Error: Firebase.createUser failed: First argument must contain the key "email" with type "string"
你可以看到代码,我使用工厂服务来处理$ createUser方法,这是发生错误的地方,因为后续的console.logs在方法返回后没有触发.请注意,我也尝试在文档中使用样板代码,而不是在控制器和服务之间拆分它并收到相同的错误.非常感谢您的帮助,谢谢!
表单元素上的ng-submit ="register()"
$scope.register = function(){
console.log($scope.user); // logs object correctly
// Authentication is passed into the controller as a dependency
Authentication.register($scope.user)
.then(function(){
//This does NOT fire
console.log("User created successfully!");
Authentication.login($scope.user);
})
.then(function(authData){
console.log("Logged in as:", authData.uid);
})
.catch(function(error) {
console.log('error');
$scope.errorMessage = error.toString();
});
};
认证工厂服务
var obj = {
register: function(user){
var obj = {email: user.email, password: user.password};
console.log(obj); // works correctly …Run Code Online (Sandbox Code Playgroud) <ul>
<li
ng-repeat="category in categoryList">
{{category.Name}} <br>
<ul>
<li
ng-repeat="game in gameList" ng-if="game.{{category.Name}}">
{{game.Name}}
</li>
</ul>
</li>
</ul>Run Code Online (Sandbox Code Playgroud)
我想检查某个游戏是否有一个具有该类别名称的孩子,括号中它只是查找一个不存在的特定孩子,称为类别.
我正在尝试使用AngularJS和Firebase构建一个Web应用程序,该应用程序向两个与某些参数匹配的用户发送电子邮件.用户首先提交他们的信息,如果与数据库中的另一个人匹配,我想向这两个人发送电子邮件.例如,如果两个人,A和B都年龄为25岁,我想向A和B发送包含特定信息的电子邮件.这可能使用Firebase吗?
所以我用requireAuth()从firebase使用开发一个Web应用程序gulpJs,angularJs和Firebase的原因.我对这三件事情都很陌生.requireAuth()方法在我的应用程序中运行良好,在线搜索内容,我遇到了$waitForAuth(),我仍然无法弄清楚差异.从名字中,人们会等待认证但是requireAuth()(显然也会等待吗?).什么时候使用它是理想的$waitForAuth(),什么时候使用它是理想的requireAuth().
myApp.factory('Authentification', function($firebase, $firebaseObject, $firebaseAuth, $routeParams, $location, FIREBASE_URL){
//not posting the other parts of the code since they are not needed in this case
var ref = new Firebase(FIREBASE_URL);
var auth = $firebaseAuth(ref);
var mytempObj = {
requireAuth: function() {
return auth.$requireAuth();
},
waitAuth: function(){
return auth.$waitForAuth();
}//wait for user to be authenticated
}
return mytempObj;
}
Run Code Online (Sandbox Code Playgroud) 考虑以下存储在 Firebase 中的数据:
{
"beers": {
"-jwhkclclmecl": {
"name": "Two Hearted Ale",
"type": "IPA",
"brewery": "Bells"
},
"-ckqjheh292od": {
"name": "Dirty Blonde Ale",
"type": "Pale Wheat",
"brewery": "Atwater"
},
"-hcwiu3cp902d": {
"name": "Diabolical",
"type": "IPA",
"brewery": "North Peak"
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否可以为 Firebase 构建查询以返回其中一个子节点的唯一值的数组。例如返回["IPA", "Pale Wheat"]
我正在使用FireBase并尝试进行一些查询,结果是登录但在HTML中不可见$scope.
var shopRef = firebaseDataService.intro;
$scope.shops = [];
var taskRef = shopRef.orderByChild("cat").equalTo("Accomodation");
taskRef.on("value", function(snapshot) {
var snapData = snapshot.val();
console.log(snapData);
$scope.shops.push(snapData);
});
Run Code Online (Sandbox Code Playgroud)
当我使用时$scope.$apply(),我设法将数据更新到商店,但它仍然没有将任何内容传递给我的指令.
<search-card shops="shops"> </search-card>
<p> Shops are {{shops}}</p>
Run Code Online (Sandbox Code Playgroud)
我用$ firebaseArray以某种方式工作了
$scope.shops = $firebaseArray(taskRef);
Run Code Online (Sandbox Code Playgroud)
但是我仍然想知道我做错了什么,以及为什么它没有使用快照.
我想从 firebase 单独加载对象的每个子项。
下面给出了一个非工作代码片段,可以更好地解释这个想法:
var userId = firebase.auth().currentUser.uid;
firebase.database().ref('/users/'+userId+"/foo/list").once('value').then(function(list) {
var reffoo = firebase.database().ref().child("/foo/");
for (var i = 0; i < list.length; i++) {
ref = reffoo.child(list[i]);
$scope.foo[ref] = $firebaseObject(ref);
}
});
Run Code Online (Sandbox Code Playgroud)
根据我的分析,问题是$firebaseObject 对 firebase 进行异步调用,但不知道如何使其工作?
我正在使用 Google Firestore。有一个名为 Universities 的集合,其中每个文档代表一所大学。
如何按名称查找大学并将其 view_count 更新为 +1?
[Collection: Universities]:
[Document: 0JsaLtcfdDaEtHLMlMrh]:{
name: The University of Sydney,
view_count: 1
};
[Document: K2z7DMhKreyDniGUpo2t]:{
name: University of New South Wales,
view_count: 2
}
Run Code Online (Sandbox Code Playgroud) 我想要一个通过使用AngularFire初始化firebase的项目。但是,在整个开发过程中,我并没有使用AngularFire的很多功能。我总是firebase/app在每项服务中导入,并使用诸如firebase.auth()或的相应功能firebase.database()。
以此经验,我想在不使用AngularFire的情况下初始化Firebase,因为我没有使用AngularFire方法。
现在出现的问题是我找不到任何教我如何初始化Firebase的资源,当然在导入Firebase时我看到错误app.module.ts。
下面是我的代码:
使用以下方法安装firebase: npm i firebase
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import * as firebase from 'firebase';
import { environment } from '../environments/environment'; //API key is imported
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
firebase.initializeApp(environment.firebase) //here shows the error
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
在的行中firebase.initializeApp(environment.firebase),显示错误:
Type …Run Code Online (Sandbox Code Playgroud) angularfire ×10
firebase ×8
angularjs ×6
javascript ×5
angular ×2
angularfire2 ×1
dom ×1
email ×1
server ×1
websocket ×1