i'm using angular to get data from an api.. the data structure i have is array(object).array(object)
- this is my data
- and this is the component ts
export class LoginComponent implements OnInit {
collaborator:Collaborator[]=[];
entreprise:Entreprise[]=[];
constructor(private serv:EntrepriseService) { }
getcoll(){
this.serv.getcollaboratorses().subscribe(res =>{
this.collaborator = res.content;
// this.entreprise=res.content.entreprise;
console.log(res);
},err =>{
console.log(err);
});
}
- the collaborator module
import {Entreprise} from './entreprise';
export interface Collaborator {
id:String;
name:String;
email:String;
password:String;
phone:String;
entreprise:Entreprise[];
roles:any[];
}
- entreprise module
export interface Entreprise {
id:String;
name:String;
socialPurpose: String;
businessCode:String;
activityDomain:String;
email:String;
password:String;
logo:String;
roles:any[];
}
- html code
<p *ngFor="let ee of collaborator">
{{ee.name}} - <ng-container *ngIf="ee?.entreprise"> {{ee.entreprise.name}} </ng-container>
</p>
when i delete this part <ng-container *ngIf="ee?.entreprise"> {{ee.entreprise.name}} </ng-container> the code works fine and i can the browser dislays all the collaborators'name but when i try to display their roles or entreprise i cannot ..
