T.S
T.S

Reputation: 55

*ngFor does not display data

I am writing my angular2 application. I have service which fetches data from database and dashboard.component.html which uses the service to display fetched data.

myService:

detailedInfo(rownum:number){
    const url='/project/users';
    return this.http.get(`${url}/${rownum}`).pipe(map((data:any)=>data));
}

dashboard.component.ts:

resultDetails:any[]=[];

checkInformation(rownum:number) {
    console.log("Details are called");
    this.myService.detailedInfo(rownum).subscribe(
        data=> {
            console.log("we got:",data);
            this.resultDetails=data;
            console.log("length of details:"+this.resultDetails.length); 
        },
        error => {
            console.log("Error",error);
        }
    );
}

dashboard.component.html:

<i (click)="checkInformation(somenumber)"></i>
<table>
    <tr  *ngFor="let res of resultDetails">
        <td >result
           <p>any text</p>
        </td>
        <td>{{res.rownumber}}</td>
    </tr>
</table>

console.log prints the correct result, but displays nothing. How can I solve the problem? thanks in advance.

Upvotes: 0

Views: 285

Answers (1)

onik
onik

Reputation: 1631

the issue is with the wrong html

  <i (click)="checkInformation(somenumber)"></i>
<table>

    <tr  *ngFor="let res of resultDetails">
        <td >result
           <p>any text</p>
        </td>
        <td>{{res.rownumber}}</td>
    </tr>

    </tr> <!-- this is extra tr remoe it 

</table>

remove extra tr

Upvotes: 1

Related Questions