Angular firestore app queries with userId not working
up vote
1
down vote
favorite
I have an angular 6 with firebase application
I have a Service with an observable (i later want multiple subscribers listening to this same observable)
and also a component that subscribes to this observable
what im trying to achieve is to get the auth object, get the userId (UID) from it and search the db for all documents with this id
the component is calling the observable at the ngOnInit hook but at the stage its still null so i get
Cannot read property 'subscribe' of undefined
the problem is that if i run the code to fill the observable inside the subscribe block (to get the auth data) that i dont get to see the data, if its outside of it (running sync using static UID) than it does get filled correctly and shows data
here is the code for the service
import Injectable, EventEmitter from '@angular/core';
import AngularFirestore, AngularFirestoreCollection, DocumentChangeAction from '@angular/fire/firestore';
import Expense from '../model/Expense';
import Observable, ReplaySubject, Subject, from from 'rxjs';
import map from 'rxjs/operators';
import AuthService from '../core/services/auth.service';
@Injectable(
providedIn: 'root',
)
export class ExpenseService
private dbPath = '/expenses';
expenseDetailEvent: EventEmitter<Expense> = new EventEmitter<Expense>();
expensesRef: AngularFirestoreCollection<Expense> = null;
expenses$: Observable<Expense>;
constructor(private db: AngularFirestore, auth: AuthService)
auth.user$.subscribe(
user =>
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', user.uid)
);
this.expenses$ = this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
);
,
error => console.log(error)
);
createExpense(expense: Expense): Observable<any>
return from(this.expensesRef.add(expense));
updateExpense(expense: Expense): Observable<any>
return from(this.expensesRef.doc(expense.id).update(expense));
and the component just does
ngOnInit()
this.expenseService.expenses$.subscribe(expenses => this.expenses = expenses);
i noticed that all the examples on line, call this on the component, but i feel that the database call should be in a service in a similar way that its done with normal http api calls
UPDATE
if i initialize the service like this
expenses$: Observable<Expense> = of();
so of course the app doesnt crash, but i dont see any data
if i just pull the code outside and use static UID than it does... (of course user.uid is the same as the static string i pasted)
here is the updated code
constructor(private db: AngularFirestore, auth: AuthService)
console.log('being here ,i see the data on screen using the static uid');
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', 'noYVScDtKfNB5aFqRkAJR7ghxio2')
);
this.expenses$ = this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
);
auth.user$.subscribe(
user =>
console.log('if inside here than it will not show any data on screen');
,
error => console.log(error)
);
angular firebase google-cloud-firestore angular6
add a comment |
up vote
1
down vote
favorite
I have an angular 6 with firebase application
I have a Service with an observable (i later want multiple subscribers listening to this same observable)
and also a component that subscribes to this observable
what im trying to achieve is to get the auth object, get the userId (UID) from it and search the db for all documents with this id
the component is calling the observable at the ngOnInit hook but at the stage its still null so i get
Cannot read property 'subscribe' of undefined
the problem is that if i run the code to fill the observable inside the subscribe block (to get the auth data) that i dont get to see the data, if its outside of it (running sync using static UID) than it does get filled correctly and shows data
here is the code for the service
import Injectable, EventEmitter from '@angular/core';
import AngularFirestore, AngularFirestoreCollection, DocumentChangeAction from '@angular/fire/firestore';
import Expense from '../model/Expense';
import Observable, ReplaySubject, Subject, from from 'rxjs';
import map from 'rxjs/operators';
import AuthService from '../core/services/auth.service';
@Injectable(
providedIn: 'root',
)
export class ExpenseService
private dbPath = '/expenses';
expenseDetailEvent: EventEmitter<Expense> = new EventEmitter<Expense>();
expensesRef: AngularFirestoreCollection<Expense> = null;
expenses$: Observable<Expense>;
constructor(private db: AngularFirestore, auth: AuthService)
auth.user$.subscribe(
user =>
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', user.uid)
);
this.expenses$ = this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
);
,
error => console.log(error)
);
createExpense(expense: Expense): Observable<any>
return from(this.expensesRef.add(expense));
updateExpense(expense: Expense): Observable<any>
return from(this.expensesRef.doc(expense.id).update(expense));
and the component just does
ngOnInit()
this.expenseService.expenses$.subscribe(expenses => this.expenses = expenses);
i noticed that all the examples on line, call this on the component, but i feel that the database call should be in a service in a similar way that its done with normal http api calls
UPDATE
if i initialize the service like this
expenses$: Observable<Expense> = of();
so of course the app doesnt crash, but i dont see any data
if i just pull the code outside and use static UID than it does... (of course user.uid is the same as the static string i pasted)
here is the updated code
constructor(private db: AngularFirestore, auth: AuthService)
console.log('being here ,i see the data on screen using the static uid');
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', 'noYVScDtKfNB5aFqRkAJR7ghxio2')
);
this.expenses$ = this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
);
auth.user$.subscribe(
user =>
console.log('if inside here than it will not show any data on screen');
,
error => console.log(error)
);
angular firebase google-cloud-firestore angular6
did you try to use ngAfterViewInit()
– Amir Fawzy
Nov 9 at 17:36
I did, no effect, the problem is that the observable is being initialized after that
– naoru
Nov 9 at 17:49
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have an angular 6 with firebase application
I have a Service with an observable (i later want multiple subscribers listening to this same observable)
and also a component that subscribes to this observable
what im trying to achieve is to get the auth object, get the userId (UID) from it and search the db for all documents with this id
the component is calling the observable at the ngOnInit hook but at the stage its still null so i get
Cannot read property 'subscribe' of undefined
the problem is that if i run the code to fill the observable inside the subscribe block (to get the auth data) that i dont get to see the data, if its outside of it (running sync using static UID) than it does get filled correctly and shows data
here is the code for the service
import Injectable, EventEmitter from '@angular/core';
import AngularFirestore, AngularFirestoreCollection, DocumentChangeAction from '@angular/fire/firestore';
import Expense from '../model/Expense';
import Observable, ReplaySubject, Subject, from from 'rxjs';
import map from 'rxjs/operators';
import AuthService from '../core/services/auth.service';
@Injectable(
providedIn: 'root',
)
export class ExpenseService
private dbPath = '/expenses';
expenseDetailEvent: EventEmitter<Expense> = new EventEmitter<Expense>();
expensesRef: AngularFirestoreCollection<Expense> = null;
expenses$: Observable<Expense>;
constructor(private db: AngularFirestore, auth: AuthService)
auth.user$.subscribe(
user =>
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', user.uid)
);
this.expenses$ = this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
);
,
error => console.log(error)
);
createExpense(expense: Expense): Observable<any>
return from(this.expensesRef.add(expense));
updateExpense(expense: Expense): Observable<any>
return from(this.expensesRef.doc(expense.id).update(expense));
and the component just does
ngOnInit()
this.expenseService.expenses$.subscribe(expenses => this.expenses = expenses);
i noticed that all the examples on line, call this on the component, but i feel that the database call should be in a service in a similar way that its done with normal http api calls
UPDATE
if i initialize the service like this
expenses$: Observable<Expense> = of();
so of course the app doesnt crash, but i dont see any data
if i just pull the code outside and use static UID than it does... (of course user.uid is the same as the static string i pasted)
here is the updated code
constructor(private db: AngularFirestore, auth: AuthService)
console.log('being here ,i see the data on screen using the static uid');
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', 'noYVScDtKfNB5aFqRkAJR7ghxio2')
);
this.expenses$ = this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
);
auth.user$.subscribe(
user =>
console.log('if inside here than it will not show any data on screen');
,
error => console.log(error)
);
angular firebase google-cloud-firestore angular6
I have an angular 6 with firebase application
I have a Service with an observable (i later want multiple subscribers listening to this same observable)
and also a component that subscribes to this observable
what im trying to achieve is to get the auth object, get the userId (UID) from it and search the db for all documents with this id
the component is calling the observable at the ngOnInit hook but at the stage its still null so i get
Cannot read property 'subscribe' of undefined
the problem is that if i run the code to fill the observable inside the subscribe block (to get the auth data) that i dont get to see the data, if its outside of it (running sync using static UID) than it does get filled correctly and shows data
here is the code for the service
import Injectable, EventEmitter from '@angular/core';
import AngularFirestore, AngularFirestoreCollection, DocumentChangeAction from '@angular/fire/firestore';
import Expense from '../model/Expense';
import Observable, ReplaySubject, Subject, from from 'rxjs';
import map from 'rxjs/operators';
import AuthService from '../core/services/auth.service';
@Injectable(
providedIn: 'root',
)
export class ExpenseService
private dbPath = '/expenses';
expenseDetailEvent: EventEmitter<Expense> = new EventEmitter<Expense>();
expensesRef: AngularFirestoreCollection<Expense> = null;
expenses$: Observable<Expense>;
constructor(private db: AngularFirestore, auth: AuthService)
auth.user$.subscribe(
user =>
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', user.uid)
);
this.expenses$ = this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
);
,
error => console.log(error)
);
createExpense(expense: Expense): Observable<any>
return from(this.expensesRef.add(expense));
updateExpense(expense: Expense): Observable<any>
return from(this.expensesRef.doc(expense.id).update(expense));
and the component just does
ngOnInit()
this.expenseService.expenses$.subscribe(expenses => this.expenses = expenses);
i noticed that all the examples on line, call this on the component, but i feel that the database call should be in a service in a similar way that its done with normal http api calls
UPDATE
if i initialize the service like this
expenses$: Observable<Expense> = of();
so of course the app doesnt crash, but i dont see any data
if i just pull the code outside and use static UID than it does... (of course user.uid is the same as the static string i pasted)
here is the updated code
constructor(private db: AngularFirestore, auth: AuthService)
console.log('being here ,i see the data on screen using the static uid');
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', 'noYVScDtKfNB5aFqRkAJR7ghxio2')
);
this.expenses$ = this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
);
auth.user$.subscribe(
user =>
console.log('if inside here than it will not show any data on screen');
,
error => console.log(error)
);
angular firebase google-cloud-firestore angular6
angular firebase google-cloud-firestore angular6
edited Nov 9 at 18:22
asked Nov 9 at 17:11
naoru
67011835
67011835
did you try to use ngAfterViewInit()
– Amir Fawzy
Nov 9 at 17:36
I did, no effect, the problem is that the observable is being initialized after that
– naoru
Nov 9 at 17:49
add a comment |
did you try to use ngAfterViewInit()
– Amir Fawzy
Nov 9 at 17:36
I did, no effect, the problem is that the observable is being initialized after that
– naoru
Nov 9 at 17:49
did you try to use ngAfterViewInit()
– Amir Fawzy
Nov 9 at 17:36
did you try to use ngAfterViewInit()
– Amir Fawzy
Nov 9 at 17:36
I did, no effect, the problem is that the observable is being initialized after that
– naoru
Nov 9 at 17:49
I did, no effect, the problem is that the observable is being initialized after that
– naoru
Nov 9 at 17:49
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
The issue is that the expenses$
Observable will be defined only after the auth.user$
has emitted something, because then is when it gets assigned.
Solution 1
You could try injecting ExpenseService
service in the constructor of a higher level component, maybe even AppComponent
, so that the ExpenseService
's constructor gets called and the expenses$
Observable gets assigned (you just need to inject it, without any method call or property access). At this point by the time you load the component the Observable should be defined
Solution 2
Manually create the Observable expenses$
using of
and then subscribing to this.expensesRef.snapshotChanges()
you can emit values back in expenses$
Something like:
...
expensesSubject = new Subject<Expense>();
expenses$: from(expensesSubject);
constructor(private db: AngularFirestore, auth: AuthService)
auth.user$.subscribe(
user =>
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', user.uid)
);
this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
).subscribe((whatever) =>
expensesSubject.next(whatever);
)
)
Can you elaborate a bit on solution 2
– naoru
Nov 9 at 18:06
I edited the answer to show the problem
– naoru
Nov 9 at 18:23
I edited the answer, typings might need to be checked but you get the idea. In the component keep everything as it is.
– Massimiliano Sartoretto
Nov 9 at 18:27
bravo, it worked but i didn't quite understand why before it wasn't working and if its necessary to use both (expenses$ and expensesSubject)
– naoru
Nov 9 at 18:34
Not necessary but a good practice. Usually you want to keepexpensesSubject
marked as private to the service and thenexpenses$
as public. This avoid components or other services being able to emit data in the stream.
– Massimiliano Sartoretto
Nov 9 at 18:40
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230394%2fangular-firestore-app-queries-with-userid-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
The issue is that the expenses$
Observable will be defined only after the auth.user$
has emitted something, because then is when it gets assigned.
Solution 1
You could try injecting ExpenseService
service in the constructor of a higher level component, maybe even AppComponent
, so that the ExpenseService
's constructor gets called and the expenses$
Observable gets assigned (you just need to inject it, without any method call or property access). At this point by the time you load the component the Observable should be defined
Solution 2
Manually create the Observable expenses$
using of
and then subscribing to this.expensesRef.snapshotChanges()
you can emit values back in expenses$
Something like:
...
expensesSubject = new Subject<Expense>();
expenses$: from(expensesSubject);
constructor(private db: AngularFirestore, auth: AuthService)
auth.user$.subscribe(
user =>
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', user.uid)
);
this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
).subscribe((whatever) =>
expensesSubject.next(whatever);
)
)
Can you elaborate a bit on solution 2
– naoru
Nov 9 at 18:06
I edited the answer to show the problem
– naoru
Nov 9 at 18:23
I edited the answer, typings might need to be checked but you get the idea. In the component keep everything as it is.
– Massimiliano Sartoretto
Nov 9 at 18:27
bravo, it worked but i didn't quite understand why before it wasn't working and if its necessary to use both (expenses$ and expensesSubject)
– naoru
Nov 9 at 18:34
Not necessary but a good practice. Usually you want to keepexpensesSubject
marked as private to the service and thenexpenses$
as public. This avoid components or other services being able to emit data in the stream.
– Massimiliano Sartoretto
Nov 9 at 18:40
add a comment |
up vote
1
down vote
accepted
The issue is that the expenses$
Observable will be defined only after the auth.user$
has emitted something, because then is when it gets assigned.
Solution 1
You could try injecting ExpenseService
service in the constructor of a higher level component, maybe even AppComponent
, so that the ExpenseService
's constructor gets called and the expenses$
Observable gets assigned (you just need to inject it, without any method call or property access). At this point by the time you load the component the Observable should be defined
Solution 2
Manually create the Observable expenses$
using of
and then subscribing to this.expensesRef.snapshotChanges()
you can emit values back in expenses$
Something like:
...
expensesSubject = new Subject<Expense>();
expenses$: from(expensesSubject);
constructor(private db: AngularFirestore, auth: AuthService)
auth.user$.subscribe(
user =>
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', user.uid)
);
this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
).subscribe((whatever) =>
expensesSubject.next(whatever);
)
)
Can you elaborate a bit on solution 2
– naoru
Nov 9 at 18:06
I edited the answer to show the problem
– naoru
Nov 9 at 18:23
I edited the answer, typings might need to be checked but you get the idea. In the component keep everything as it is.
– Massimiliano Sartoretto
Nov 9 at 18:27
bravo, it worked but i didn't quite understand why before it wasn't working and if its necessary to use both (expenses$ and expensesSubject)
– naoru
Nov 9 at 18:34
Not necessary but a good practice. Usually you want to keepexpensesSubject
marked as private to the service and thenexpenses$
as public. This avoid components or other services being able to emit data in the stream.
– Massimiliano Sartoretto
Nov 9 at 18:40
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
The issue is that the expenses$
Observable will be defined only after the auth.user$
has emitted something, because then is when it gets assigned.
Solution 1
You could try injecting ExpenseService
service in the constructor of a higher level component, maybe even AppComponent
, so that the ExpenseService
's constructor gets called and the expenses$
Observable gets assigned (you just need to inject it, without any method call or property access). At this point by the time you load the component the Observable should be defined
Solution 2
Manually create the Observable expenses$
using of
and then subscribing to this.expensesRef.snapshotChanges()
you can emit values back in expenses$
Something like:
...
expensesSubject = new Subject<Expense>();
expenses$: from(expensesSubject);
constructor(private db: AngularFirestore, auth: AuthService)
auth.user$.subscribe(
user =>
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', user.uid)
);
this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
).subscribe((whatever) =>
expensesSubject.next(whatever);
)
)
The issue is that the expenses$
Observable will be defined only after the auth.user$
has emitted something, because then is when it gets assigned.
Solution 1
You could try injecting ExpenseService
service in the constructor of a higher level component, maybe even AppComponent
, so that the ExpenseService
's constructor gets called and the expenses$
Observable gets assigned (you just need to inject it, without any method call or property access). At this point by the time you load the component the Observable should be defined
Solution 2
Manually create the Observable expenses$
using of
and then subscribing to this.expensesRef.snapshotChanges()
you can emit values back in expenses$
Something like:
...
expensesSubject = new Subject<Expense>();
expenses$: from(expensesSubject);
constructor(private db: AngularFirestore, auth: AuthService)
auth.user$.subscribe(
user =>
this.expensesRef = this.db.collection<Expense>(this.dbPath, ref =>
ref.where('clientId', '==', user.uid)
);
this.expensesRef.snapshotChanges().pipe(
map(actions =>
actions.map(a =>
const data = a.payload.doc.data() as Expense;
const id = a.payload.doc.id;
return id, ...data ;
)
)
).subscribe((whatever) =>
expensesSubject.next(whatever);
)
)
edited Nov 9 at 18:26
answered Nov 9 at 18:03
Massimiliano Sartoretto
31618
31618
Can you elaborate a bit on solution 2
– naoru
Nov 9 at 18:06
I edited the answer to show the problem
– naoru
Nov 9 at 18:23
I edited the answer, typings might need to be checked but you get the idea. In the component keep everything as it is.
– Massimiliano Sartoretto
Nov 9 at 18:27
bravo, it worked but i didn't quite understand why before it wasn't working and if its necessary to use both (expenses$ and expensesSubject)
– naoru
Nov 9 at 18:34
Not necessary but a good practice. Usually you want to keepexpensesSubject
marked as private to the service and thenexpenses$
as public. This avoid components or other services being able to emit data in the stream.
– Massimiliano Sartoretto
Nov 9 at 18:40
add a comment |
Can you elaborate a bit on solution 2
– naoru
Nov 9 at 18:06
I edited the answer to show the problem
– naoru
Nov 9 at 18:23
I edited the answer, typings might need to be checked but you get the idea. In the component keep everything as it is.
– Massimiliano Sartoretto
Nov 9 at 18:27
bravo, it worked but i didn't quite understand why before it wasn't working and if its necessary to use both (expenses$ and expensesSubject)
– naoru
Nov 9 at 18:34
Not necessary but a good practice. Usually you want to keepexpensesSubject
marked as private to the service and thenexpenses$
as public. This avoid components or other services being able to emit data in the stream.
– Massimiliano Sartoretto
Nov 9 at 18:40
Can you elaborate a bit on solution 2
– naoru
Nov 9 at 18:06
Can you elaborate a bit on solution 2
– naoru
Nov 9 at 18:06
I edited the answer to show the problem
– naoru
Nov 9 at 18:23
I edited the answer to show the problem
– naoru
Nov 9 at 18:23
I edited the answer, typings might need to be checked but you get the idea. In the component keep everything as it is.
– Massimiliano Sartoretto
Nov 9 at 18:27
I edited the answer, typings might need to be checked but you get the idea. In the component keep everything as it is.
– Massimiliano Sartoretto
Nov 9 at 18:27
bravo, it worked but i didn't quite understand why before it wasn't working and if its necessary to use both (expenses$ and expensesSubject)
– naoru
Nov 9 at 18:34
bravo, it worked but i didn't quite understand why before it wasn't working and if its necessary to use both (expenses$ and expensesSubject)
– naoru
Nov 9 at 18:34
Not necessary but a good practice. Usually you want to keep
expensesSubject
marked as private to the service and then expenses$
as public. This avoid components or other services being able to emit data in the stream.– Massimiliano Sartoretto
Nov 9 at 18:40
Not necessary but a good practice. Usually you want to keep
expensesSubject
marked as private to the service and then expenses$
as public. This avoid components or other services being able to emit data in the stream.– Massimiliano Sartoretto
Nov 9 at 18:40
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230394%2fangular-firestore-app-queries-with-userid-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
did you try to use ngAfterViewInit()
– Amir Fawzy
Nov 9 at 17:36
I did, no effect, the problem is that the observable is being initialized after that
– naoru
Nov 9 at 17:49