简体   繁体   English

“从不”类型上不存在属性 - 在 ngFor 变量上

[英]Property does not exist on type 'never' - on ngFor variable

When I'm trying to get responses from API, I use an ngFor for dynamically sorting my view.当我试图从 API 获得响应时,我使用 ngFor 对我的视图进行动态排序。 Here's the line of code:这是代码行:

  <agm-marker *ngFor="let httpResponses of response" [latitude]= "httpResponses.lat" [longitude]="httpResponses.lng"
        [agmFitBounds]="true">

To be more clear:为了更清楚:

... *ngFor="let httpResponses of response" [latitude]= "httpResponses.lat" [longitude]="httpResponses.lng" ... ... *ngFor="let httpResponses of response" [latitude]= "httpResponses.lat" [longitude]="httpResponses.lng" ...

and it gives automatically the type of httpResponses as never .它会自动将 httpResponses 的类型设为never And because of that gives these errors below:正因为如此,下面给出了这些错误:

error TS2339: Property 'lng' does not exist on type 'never'.错误 TS2339:“从不”类型上不存在属性“lng”。

error TS2339: Property 'lat' does not exist on type 'never'.错误 TS2339:“从不”类型上不存在属性“纬度”。

Can I declare any Typescript type on httpResponse in the Html file?我可以在 Html 文件中的 httpResponse 上声明任何 Typescript 类型吗? The project works fine, I get the lat and lng values from httpResponses and display it, but however I constantly get these errors, I tried to declare type on httpResponses in component.ts file, it didn't change anything.该项目工作正常,我从 httpResponses 获取 lat 和 lng 值并显示它,但是我不断收到这些错误,我试图在 component.ts 文件中声明 httpResponses 的类型,它没有改变任何东西。

Thanks for any advice.感谢您的任何建议。

You should use bracket notation instead of dot notation for accessing property:您应该使用括号表示法而不是点表示法来访问属性:

<agm-marker *ngFor="let httpResponses of response" [latitude]= "httpResponses['lat']" [longitude]="httpResponses['lng']"
        [agmFitBounds]="true">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM