I am working with Angular 8 for a web app. So I have a backend in which I have implemented some get http call. They all should return an array of objects.
My array of object has an interface of this type:
export interface MssInterface {
operatingroom: number;
sessionid: number;
specialty: number;
day: number;
}
I have created a mssService.ts to put all the GET together (in the environment.backendURL variable there is the first part of the address: http://localhost4200)
export class MssService {
mssURL = environment.backendURL + "/api/mss";
constructor(private http: HttpClient) { }
getS1(): Observable<MssInterface> {
return this.http.get<MssInterface>(this.mssURL + '/uno');
}
Then I have a component class in which I am subscribing to the mssService to fetch the data. So i have written my home.component.ts like this:
export class HomeComponent implements OnInit {
mssData: MssInterface;
constructor(public mssService: MssService)
mssToDisplayOne() {
this.mssService.getS1().subscribe((MSS) => {
this.mssData = MSS;
console.log(this.mssData);
});
}
...
}
Everything seems to work properly except that when I go to make a *ngFor inside the array of objects in the html code, it doesn’t return anything.
home.component.html :
<tr *ngFor="let item of mssData">
<td *ngIf="item.sessionid %2==1"> {{item.operatingroom}} </td>
<td *ngIf="item.sessionid %2==0"> {{item.operatingroom}} </td>
</tr>
I have tried to understand why nothing happend doing this thing :
<tr *ngFor="let item of mssData">
<td>{{ item | json}}</td>
</tr>
And with this it displays my entire array of Objects. here the displayed object
So, what Am I doing wrong? Why it can't read inside my array of objects?