我从后端返回的对象数组如下所示:
"courses":
[
{
"_id": "5a0eb3d7f6b50c2589c34e57",
"name": "Js",
"started": 1990,
"author": "Author",
"description": "Building static pages is great, but sometimes we need to feed dynamic content into our templates. Because Perk is built on top of Express, it supports all the templating engines and ships with ejs. ",
"lessons": 1,
"__v": 0,
"subscribers": [],
"tasks": [
"fwefwfwrfrewgerg"
],
"lectures": [
"qefefwefweqd"
]
},
{
"_id": "5a2e789db3f2bc195cbfafe2",
"name": "erg",
"started": 1990,
"author": "ergeg",
"description": "ergreg",
"lessons": 1,
"image": "https://res.cloudinary.com/dk34qvajk/image/upload/v1512994973/yjq40xtrarwi3sgrbwgn.jpg",
"__v": 0,
"subscribers": [],
"tasks": [
"ergerg"
],
"lectures": [
"ergerg"
]
}
]
我尝试使用
ng-repeat="course in courses"进行迭代,并在html文件中显示{{course.name}},作者等的课程名称,但收到错误
courses.component.ts
ngOnInit() {
this.authService.getCourses().subscribe(data=>{
this.courses = data.courses;
console.log(this.courses)
},
err=>{
console.log(err);
return false;
});
}