Angular出现TS2339错误:Projects[]类型不存在title属性的问题求助
问题解决:TS2339 "Property 'title' does not exist on type 'Projects[]'"
错误根源
你在project-list.component.html的*ngFor循环中,错误地尝试访问数组projects的title属性——projects是Projects[]类型的数组,本身并不具备title属性,title属于数组内的单个Projects对象。
修复代码
修改project-list.component.html中的变量引用,使用循环迭代出的单个项目对象访问属性:
project-list.component.html <p *ngFor="let tempProject of projects"> {{ tempProject.title }} </p>
额外验证(可选)
若修复后仍有问题,可确认以下两点:
- 后端返回的
_embedded.projects结构与GetResponse接口定义一致,每个项目对象确实包含title字段 Projects类的属性名与后端返回的字段名完全匹配(大小写敏感)
内容的提问来源于stack exchange,提问作者user13372981
相关产品推荐
相关产品推荐

