angularfire2

What's the best way to get data from collections nested in documents in Firestore?

ぃ、小莉子 提交于 2019-12-03 07:36:07
问题 I'm going through the Firestore docs and guide. My code samples below use AngularFire2. Let's consider a "chats" collection similar to the examples provided here: https://firebase.google.com/docs/firestore/manage-data/structure-data They recommend this kind of structure but I don't see where they discuss getting all the data efficiently. Each chat document has properties, a collection of members, and a collection of messages: chatsCollection chatDocument [insert chat data fields here]

How do I get the current user's access token in AngularFire2?

你离开我真会死。 提交于 2019-12-03 06:59:26
In AngularFire you were able to access the providers (e.g Google) accessToken for the authenticated user. There does not seem to be a way to access this with AngularFire2? On initial login say like this: this.af.auth.subscribe(user=> { if (user) { console.log(user.google); } }); It will log out the idToken, accessToken, provider, But (on a page refresh) subsequently will log out the standard details (uid, displayName etc....) And the accessToken is not an accessible property? Is there a way to access the current users accessToken? getToken is deprecated now. You should use getIdToken instead:

Firebase error messages in different languages?

ε祈祈猫儿з 提交于 2019-12-03 06:11:40
Showing the Firebase error messages (error.message) in the view results in english error descriptions (e.g. for Authentication errors, if user credetials contain errors). How would you display the messages in different languages (best case: in the phone's language)? This is impossible right now. What I recommend is to use the erros code (error.code) that is a unique error code and with that you can create something to bind this errors code to your own text/language. There is an available page at Firebase documentation that have a list of those errors code that might help you with that. Check

Pagination using AngularFire2

两盒软妹~` 提交于 2019-12-03 05:12:08
I am building an Ionic2 project, that uses Firebase and I am using AngularFire2. From AngularFire2 documentation, I was able to get things like: const queryObservable = af.database.list('/items', { query: { orderByChild: 'size', equalTo: subject } }); This works well. I have around 300-400 records, but I can't pull it all in one API call. So I am trying to implement pagination. I tried many things. What I want to implement is this : StartAt(), endAt() I tried to pass it through the query object, but it did not work. Does AngularFire2 have an implementation for this? If not, how can I get the

Using BehaviorSubject in auth-guard's canActivate

你说的曾经没有我的故事 提交于 2019-12-03 03:59:01
What I want to achieve: I want to share authentication state across my application using BehaviorSubject. I use the authentication state e.g. inside an auth-guard to prevent the user from visiting login/register pages when the user already is authenticated. Problem: because the BehaviorSubject has a initial value, which is false (not logged in), it seems that the auth-guard takes this first value, instead of waiting for the uid-sync. AuthInfo (Auth state store): export class AuthInfo { constructor(public uid: string) {} isLoggedIn() { return !!this.uid; } } AuthService : @Injectable() export

Access parent documents field in Firestore rules

心已入冬 提交于 2019-12-03 03:09:52
I'm implementing a recipe book in Firestore where every user is able to see all the recipes all users created but only the original author of the recipe is allowed to edit or delete the recipe. Any user is also allowed to create a new recipe. My problem is that I am unable to setup the permissions a subcollection to "listen" on a field of the subcollections parentdocument. Each recipe document contains three things. A field called name where the name of the recipe is stored, a field called creatorUID where the request.auth.uid of the creators uid is stored and a subcollection called

How to mock AngularFire 2 service in unit test?

夙愿已清 提交于 2019-12-03 02:09:35
I'm trying to set up unit tests for a sample Angular 2 app using AngularFire 2 auth, the component is fairly simple: import { Component } from '@angular/core'; import { AngularFire, AuthProviders } from 'angularfire2'; @Component({ moduleId: module.id, selector: 'app-root', templateUrl: 'app.component.html', styleUrls: ['app.component.css'] }) export class AppComponent { isLoggedIn: boolean; constructor(public af: AngularFire) { this.af.auth.subscribe(auth => { if (auth) { this.isLoggedIn = true; } else { this.isLoggedIn = false; } }); } loginWithFacebook() { this.af.auth.login({ provider:

I want to calculate the sum of the ShoppingCart at Firebase with Angularfire2

◇◆丶佛笑我妖孽 提交于 2019-12-02 22:13:31
问题 I'm building an experimental application that uses Angular2, Firebase and AngularFire2. This is what my data looks like: { "ShoppingCartItem": { "item1":{ "quantity": 2, "productId": "abc" }, "item2":{ "quantity": 1, "productId": "bcd" } } "Product" { "abc":{ "name": "product1", "price": 5 }, "bcd":{ "name": "product2", "price": 6 } } } Below are my cart.ts this.items = this.af.database.list('ShoppingCartItem') .map(carts => { return carts.map(item => { item.product = this.af.database.object(

What's the best way to get data from collections nested in documents in Firestore?

南楼画角 提交于 2019-12-02 21:08:04
I'm going through the Firestore docs and guide. My code samples below use AngularFire2. Let's consider a "chats" collection similar to the examples provided here: https://firebase.google.com/docs/firestore/manage-data/structure-data They recommend this kind of structure but I don't see where they discuss getting all the data efficiently. Each chat document has properties, a collection of members, and a collection of messages: chatsCollection chatDocument [insert chat data fields here] membersCollection memberDocument [insert member data fields here] messagesCollection messageDocument [insert

Three way binding in Angular 2 and Angularfire2

拈花ヽ惹草 提交于 2019-12-02 20:59:21
I am trying to three-way bind an input element to firebase database in Angular.js 2 (2.0.0-rc.4), using AngularFire 2 (2.0.0-beta.2). I have a very simple html like: <form (ngSubmit)="onSubmit()" #commentForm="ngForm"> <input [(ngModel)]="model.author" type="input" name="author" required> </form> In my component, to save and retrieve contents of this input to firebase, I have an implementation like this: export class CommentFormComponent implements OnInit, AfterViewInit { @ViewChild("commentForm") form; // http://stackoverflow.com/questions/34615425/how-to-watch-for-form-changes-in-angular-2