我有一个 Angular 项目,在项目中,我有一个服务,它返回一个对象,在应用程序组件中,我正在使用该对象。
theobject.profileImg
一切正常,但 Idm 显示此错误。 “'object' 类型上不存在属性 'profileImg'。”
我正在使用 vsCode
最佳答案
在模板中使用如下:
theobject?.profileImg
或者
theobject['profileImg']
但通常更好地将模型添加到您的对象中,例如:
theobject: IObject;
和
interface IObject {
profileImg: string;
id: number;
//and more
}
关于angular - 如何忽略 typescript 或 idm 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59749858/