gpt4 book ai didi

javascript - 如何使用 Angular 获取典型的 json 数据

转载 作者:行者123 更新时间:2023-11-28 16:50:39 25 4
gpt4 key购买 nike

import {
Component,
OnInit
} from '@angular/core';
import {
ResumedataService
} from "../../services/resumedata.service";

@Component({
selector: 'app-projects',
templateUrl: './projects.component.html',
styleUrls: ['./projects.component.scss']
})
export class ProjectsComponent implements OnInit {
projectdata: any = [];
constructor(private resumeservice: ResumedataService) {}

ngOnInit() {
// service call
this.resumeservice.getresumedata().subscribe(data => (this.projectdata = data.projects));
}

}
<div *ngFor="let item of projectdata">
<h5>{{item.projectName}}</h5>
<span>{{item.technologies.tech}}</span>
</div>

//******this is jason data******* "projects": [ { "id":1, "projectName": "Flight Reservation System", "technologies": [ {"tech":"html"}, {"tech":"css"}, {"tech":"javascript"}, {"tech":"jquery"}, {"tech":"sql"}, {"tech":"angular"} ] }, { "id":2, "projectName":
"Train Reservation System", "technologies": [ {"tech":"html"}, {"tech":"css"}, {"tech":"javascript"}, {"tech":"jquery"}, {"tech":"sql"}, {"tech":"angular"} ] } ]

上面是我的源代码,您可以看到我想获取数据,因为我成功获取了项目的名称,但是名为“技术”的对象有子对象,所以我如何获取它们看看是否有任何子对象错误..??

最佳答案

只需使用另一个*ngFor:

<div *ngFor="let item of data">
{{item.projectName}}
<br />
<ul *ngFor="let t of item.technologies">
<li>{{t.tech}}</li>
</ul>
</div>

https://stackblitz.com/edit/angular-3xsmgy?file=src/app/app.component.html

希望对你有帮助!

关于javascript - 如何使用 Angular 获取典型的 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60000847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com