如何将()=>数字转换为Angular中的数字

时间:2019-07-09 10:31:32

标签: angular typescript

我在转换时遇到问题。 我收到这样的错误:

  

类型'()=>数字'不能分配给类型'数字'。

在这部分代码中:

...
for (let g of parcelData.geom){
      const point = [];
      let lat : number;
      lat = g.lat; // error there
...

有人可以告诉我如何将其转换为经典数字吗?

2 个答案:

答案 0 :(得分:3)

g.lat()是一个函数,您应该像下面这样分配它。

lat = g.lat()

答案 1 :(得分:0)

  

注意

首先检查parcelData.geom的数据类型

console.log(typeof parcelData.geom);

然后根据以下内容更改

let lat : number;<----then change this
  lat = g.lat;