angularfire2

Casting FirebaseListObservable results to objects

纵饮孤独 提交于 2019-12-05 21:21:01
I'm using angularfire-beta6. Let's say I have a myHeroes:FirebaseListObservable<Hero[]> and use it with an async -pipe in my template I cannot access functions from the Hero class. <ul> <li *ngFor="let hero of myHeroes"> {{hero.someClassFunction()}} </li> </ul> This results in an error: self.context.$implicit.someClassFunction() as hero is not cast to the Hero class. How would I do that? You can get an object or a list from the database using list or object function on AngularFireDatabase . You have FirebaseListObserver with an array of objects of predefined (not your custom) class. Your will

How to pass a value inside an observable to (click) handler in Angular2

浪尽此生 提交于 2019-12-05 20:34:27
I try to learn observable programming with Angular 2 BUT I don't get one important point - how to pass in the value that is in an observable in the (click) event in the template level (without subscribing the observable in the TS file and turn the observable value into member variable). As lots of Firebase experts suggest this "Wherever possible, try to use | async in angular2 and prevent manual subscriptions!" - reason for not wanting to manually subscribe to task$ and turn it into an array. For example: I have this in my TS file of component: task$: Observable<Task>; this.task$ = this

When is catch() called when using docRef.get() in FireStore?

一曲冷凌霜 提交于 2019-12-05 19:28:40
In Angular 5 with FireStore and angularfire2, when retrieving the contents of a single document using docRef.get() , what scenario would cause the catch statement to be executed? How can I produce such an error? If I interpret the note below the code correctly, it means that if there is no document , it will return null , rather than throwing an error. So my question is, in what case would it actually throw an error and go into the catch statement? 来源: https://stackoverflow.com/questions/49132183/when-is-catch-called-when-using-docref-get-in-firestore

How to retrieve the Id of a single Firestore document?

痴心易碎 提交于 2019-12-05 09:26:35
This is my code: import { Component, OnInit } from '@angular/core'; import { AngularFirestore , AngularFirestoreCollection , AngularFirestoreDocument } from 'angularfire2/firestore'; import { Observable } from 'rxjs/Observable'; interface Country { id?: string; name?: string; code?: string; flag?: string; continent?: string; } @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { title = 'Firestore - Documents'; private countryRef: AngularFirestoreCollection<Country>; docId: any; constructor(

How to use snapshotChanges() method to get both key value and filter the data?

▼魔方 西西 提交于 2019-12-05 08:14:18
I'm working on an Angular Firebase Project, where I need to filter my database as well get the key values. Currently I'm using valueChanges() method in my service code ( inside getUnreadBooks and getFavoriteBooks methods, as shown below ) to get the data and filter it. But it gives me key value as 'undefined', when I try to get key value inside my template file. I tried to go with snapshotChanges() method, but can't work around how to use it to get key values along with filtering the data . Below are my Angular FirebaseService, home.component.ts ( in which I am injecting my service code ) and

AngularFire2 infinite scrolling

懵懂的女人 提交于 2019-12-05 03:20:46
问题 I'm trying to implement an infinite scrolling with Ionic2 and Firebase. I use AngularFire2. What I'd like to do is to add new items to the fetched list and not to reload the whole list. let query$:Observable<any> = this.af.database.list(`quests/`, { query: { orderByChild: 'date_published', limitToFirst: this.recentChunkLimit$ //Subject where I push new limit length } }).publishReplay(1).refCount(); However, when I query list like that, the whole list is reloaded each time via websockets

Firebase Realtime Database currently gives TRIGGER_PAYLOAD_TOO_LARGE error

房东的猫 提交于 2019-12-05 02:30:47
Since this morning, our Firebase application has a problem when writing data to the Realtime Database instance. Even the simplest task, such as adding one key-value pair to an object triggers Error: TRIGGER_PAYLOAD_TOO_LARGE: This request would cause a function payload exceeding the maximum size allowed. It is especially strange since nothing in our code or database has changed for more than 24 hours. Even something as simple as Database.ref('environments/' + envkey).child('orders/' + orderkey).ref.set({a:1}) triggers the error. Apperently, the size of the payload is not the problem, but what

How can I use two translators first for JSON file and second for firestore?

不问归期 提交于 2019-12-04 20:42:55
JSON File Method export function createTranslateLoader(http: HttpClient) { return new TranslateHttpLoader(http, './assets/i18n/', '.json'); } JSON File Loader TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: (createTranslateLoader), deps: [HttpClient] } }), AngularFirestore Method export function FirestoreTranslationsLoaderFactory(db: AngularFirestore) { return new FirestoreTransLoader(db); } AngularFirestore File Loader TranslateModule.forRoot({ loader: { provide: TranslateLoader, useFactory: FirestoreTranslationsLoaderFactory, deps: [AngularFirestore] } }), Note: I

How to move FirebaseObjectObservable into a FirebaseListObservable

时光毁灭记忆、已成空白 提交于 2019-12-04 17:55:22
I'm having trouble moving a FirebaseObjectObservable into a FirebaseListObservable. constructor( af: AngularFire, private cs: ContactsService, public modalCtrl: ModalController ) { // Getting Friends this.friends = af.database.list('/userFriends/jvi1cjPwddPomjEDNwv3VihskOX2/') .map((friends)=>{ return friends.map((friend) => { friend = af.database.object('/users/'+friend.$key); return friend; }) }); } When I log it to the console. I end up with an array of FirebaseObjectObservables. How can I move this into a FirebaseListObservable so that I can use the async pipe to render the objects. My

Property 'subscribe' does not exist on type Auth

吃可爱长大的小学妹 提交于 2019-12-04 17:26:28
With the code below, I am getting the error Property 'subscribe' does not exist on type Auth . If I remove the entire block of subscribe code from app.component.ts then I am getting no error, but the browser is opening directly on the home page and not the login page. At the bottom of app.component.html I have included <router-outlet></router-outlet> , app.component.ts import { Component } from '@angular/core'; import { Router } from '@angular/router'; import { Observable } from 'rxjs/Observable'; import { AngularFireModule } from 'angularfire2'; import { AngularFireDatabaseModule,