【发布时间】:2020-03-21 16:36:30
【问题描述】:
我在我的组件中执行正常的 http get 请求,并在 html 中显示结果,一切正常,但是当我打开控制台时出现错误。 '无法读取未定义的属性'内容'。
<div class="container myPadding">
<div class="form-row justify-content-center">
<h1>Substances</h1>
</div>
<div class="form-row justify-content-center">
<p class="alert alert-info">
Total Substances registered: ({{ substanceList.totalElements }})
</p>
</div>
<a>
<table class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>Substance Name</th>
</tr>
</thead>
<tbody *ngFor="let response of substanceList.content | slice:0:99">
<tr>
<td>{{response.neo4jId}}</td>
<td>{{response.substanceName}}</td>
</tr>
</tbody>
</table>
</a>
和ts文件
export class SubstancesComponent implements OnInit, OnDestroy {
substanceList: any;
subscription: Subscription;
constructor(private http: HttpClient, private drugService: DrugsService) { }
ngOnInit() {
this.getAllSubstances();
}
getAllSubstances() {
this.subscription = this.drugService.getSubstances().subscribe(response => {
this.substanceList = response;
console.log(this.substanceList);
})
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
}
这是我的服务中的功能
getSubstances(): any {
return this.http.get(environment.substancesUrl);
}
浏览器中的结果是我想要的结果,但是这个错误出现在控制台中,我想了解为什么会出现这个错误以及如何解决这个问题。
【问题讨论】:
-
有人在.cmets 中提到了类似的消息:stackoverflow.com/questions/45808908/…“它与导入文件的拼写错误有关”您必须截取整个消息或复制/粘贴它以某种方式更加确定。
-
内容是您响应的属性?您是否使用 *ngFor 在您的 html 上呈现数据?
标签: angular