要在Angular中使用*ngFor来显示来自HTTP响应的内容,你需要遵循以下步骤:
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
constructor(private http: HttpClient) { }
getData(): Observable {
return this.http.get('your-api-url');
}
data: any[];
ngOnInit() {
this.getData().subscribe(response => {
this.data = response;
});
}
{{ item.property }}
确保将'your-api-url'替换为你实际的API地址,并将'property'替换为你实际的属性名称。
这样就可以使用*ngFor来显示来自HTTP响应的内容了。