Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular ngFor以角度6显示空数据行_Angular - Fatal编程技术网

Angular ngFor以角度6显示空数据行

Angular ngFor以角度6显示空数据行,angular,Angular,我试图让我的第一个Angular 6应用程序工作,但我在这个问题上卡住了。我想显示系统中的用户列表。从服务器接收用户,但显示时,值为空。我有3个用户,然后列表显示了正确的用户数量,但值为空。 包含3个不可见用户的列表。 接收数据时,我将其记录到控制台,以查看数据是否存在: 我的代码: user-list.component.ts <table class="table table-sm table-hover"> <tr *ngFor="let usr of userS

我试图让我的第一个Angular 6应用程序工作,但我在这个问题上卡住了。我想显示系统中的用户列表。从服务器接收用户,但显示时,值为空。我有3个用户,然后列表显示了正确的用户数量,但值为空。 包含3个不可见用户的列表。

接收数据时,我将其记录到控制台,以查看数据是否存在:

我的代码: user-list.component.ts

<table class="table table-sm table-hover">
  <tr *ngFor="let usr of userService.UserList">
    <td>{{usr.FirstName}} - {{usr.LastName}}</td>
    <td>{{usr.Id}}</td>
    <td>
      <a class="btn" (click)="showForEdit(employee)">
        <i class="fa fa-pencil-square-o"></i>
      </a>
      <a class="btn text-danger" (click)="onDelete(user.Id)">
        <i class="fa fa-trash-o"></i>
      </a>
    </td>
  </tr>
</table>
您正在使用
usr.FirstName
但您的属性类似于
usr.FirstName
。当出现这种神奇的情况时,一定要检查打字错误,如99%的问题是这样。

修复了错误。谢谢我不知道它变成了小写。在我的user.model.ts中,所有字段都使用like FirstName和LastName,因此我在html中使用了相同的拼写。我想我今天学到了一件新东西:)你的模型与当时的数据不符。
getUserList() {
  this.http.get('https://localhost:5001/api/user/').pipe(map(data => {
    return data.json() as User[];
  }
  )).toPromise().then(x => {
    this.UserList = x;
    console.log(this.UserList);
  })
}