1

In collection companies there's a documents with model

company: example
address: nowhere
users:{
  123456789:{
   email: [email protected]
  }
}

where 123456789 is user's id

To get data from documents

this.compColl = this.afs.collection('companies');
this.comp = this.compColl.valueChanges();

To list data in view

<li *ngFor="let cmp of comp | async">{{cmp.company}}</li>

This working for fields company and address but not working for

<li *ngFor="let cmp of comp | async">{{cmp.email}}</li>

How to list users email from this document

5
  • To acces email, you need to access two other objects which are users and 123456789 which is probably the user ID. Commented May 26, 2018 at 2:08
  • I thought so, but I don't know how to access user Id when there is no chance to know what is user id and there could be more users in one document. Should I remodel document to access users IDs Commented May 26, 2018 at 2:27
  • Try this<li *ngFor="let user of comp.users | async">{{user.email}}</li> Commented May 26, 2018 at 2:30
  • No, that's not working Commented May 26, 2018 at 8:59
  • Where is any ARRAY....?? Commented Jun 15, 2022 at 14:28

1 Answer 1

1
users:{
  123456789:{
   email: [email protected]
  }
}

If you want to get [email protected] you can use

<li *ngFor="let cmp of comp | async">{{cmp.users[123456789].email}}</li>

users is an object and not an array so you can't use <li *ngFor="let user of comp.users | async">{{user.email}}</li>. If you want to use it, your database should return something like this:

company: example
address: nowhere
users:[ //instead of {
  123:{
   email: [email protected]
  },
  456:{
   email: [email protected]
  },
] //instead of }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.