html - 当使用 GET 方法时,数据进入控制台而不是 HTML
问题描述
我在里面写了我的get方法ngOnInIt()
。当我在控制台中打印数据时,它是可见的,但是当使用插值在 HTML 中打印时,它正在返回[ object object]
{{filteredCourses}} ==> [对象对象]
当我使用 {{course.category|json}} 所以在这里我得到数组的所有值 ["course" : "database" , "category" : "database" , "length" : "2hr" ] 就是这样价值来了
html:-
<div class="courses" fxLayout="row wrap" fxLayoutAlign="center" [@animateStagger]="{value:'50'}">
<div class="course" *ngFor="let course of filteredCourses" fxFlex="100" fxFlex.gt-xs="50"
fxFlex.gt-sm="33" [ngClass]="course.category" [@animate]="{value:'*',params:{y:'100%'}}">
<div class="course-content" fxLayout="column" fxFlex="1 1 auto">
<div class="header" fxLayout="row" fxLayoutAlign="center center"
[ngClass]="course.category + '-bg'">
<div class="category" fxFlex>
{{course.category|json}}
</div>
</div>
</div>
代码:filteredCourses:any[];
this.product_name = getProduct()['name'];
console.log(this.product_name);
this.token = getToken();
this.httpHeaders = new HttpHeaders({ "Authorization": "Bearer " + this.token });
this._httpClient.get('http://127.0.0.1:8000/api/products/info/'+this.product_name+'/',{headers: this.httpHeaders})
.subscribe(
data => {
this.product = data;
this.courses = data['cources'];
this.filteredCourses = this.courses;
console.log(this.filteredCourses);
},
error => {
console.log(error);
}
);
解决方案
我想filteredCourses 集合包含一个对象数组。因此,您需要使用 ngFor 指令遍历过滤的课程,以在 HTML 模板中呈现数据。
喜欢:
<ul>
<li ngFor="let item of filteredCourses">{{item.courseName}}</li>
</ul>
推荐阅读
- php - Mailtrap 不适用于 Wordpress localhost(在 Xampp 上运行)
- php - CURL API 用 php 和 html 在表格中显示数据
- c++ - Docker 镜像问题查找头文件
- java - 在解决类路径问题时,getproperty() 和 getPackage().getImplementationVersion() 返回 null
- php - 如何在父类方法中克隆子类实例
- android - ConstraintLayout 中的 Start 和 Left 有什么区别?
- python - 如何在两列上的两个数据框之间创建合并,而不在左侧引入额外的行?
- visual-studio-code - 键绑定:焦点编辑器的索引是否有“when”子句,或者它是否是最后一个?
- layout - 如何在 SwiftUI 中跨多个轴对齐多个视图?
- python - 如何将由整数和浮点数组成的列表中的字符串列表转换为整数和浮点数?