角度:错误TS2339:类型“对象”上不存在属性“数据”

 收藏

我是Angular的初学者,遇到一个奇怪的错误,它说它没有在API对象中找到属性数据,而我试图从一个简单的API中获取数据,并将其显示在我的页面中,这是代码。

export class ArticlesComponent implements OnInit {
 users: Object;

  constructor(private data: DataService) { }

  ngOnInit(): void {
    this.data.getUsers().subscribe(data=>{
      this.users=data;
      console.log(this.users);

    });
  }


}

模板就是这样

<ul *ngIf="users">
  <li *ngFor="let user of users.data">
    <img [src]="user.avatar">
     <p>{{user.first_name}} {{user.last_name}}</p>
  </li>
</ul>

I have been stock here for hours. When I console log, there is a data property and has all the information of the users, that is what I am trying to display, it shows me that does not exist. and here is the API link : https://reqres.in/api/users Please help.

回复