【发布时间】:2019-07-18 15:08:58
【问题描述】:
我正在尝试在我的 Angular 7 应用程序中使用 latlon-geohash npm 包,但是当我运行它时,我收到了这个错误...
错误类型错误:latlon_geohash__WEBPACK_IMPORTED_MODULE_8__.encode 是 不是函数
这是我的代码:
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import * as gh from 'latlon-geohash';
@Component({
selector: 'app-account',
templateUrl: './account.component.html',
styleUrls: ['./account.component.scss'],
})
export class AccountComponent implements OnInit {
constructor() {
}
ngOnInit() {
//Here I'm trying to encode my lat and lng to a GeoHash
console.log(gh.encode(39.36, -76.69, 4))
}
}
而且它不起作用。但是,当我运行console.log(gh) 时,我得到了这个...
Module {default: ƒ, __esModule: true, Symbol(Symbol.toStringTag): "Module"}
default: class Geohash
adjacent: ƒ adjacent(geohash, direction)
arguments: (...)
bounds: ƒ bounds(geohash)
caller: (...)
decode: ƒ decode(geohash)
encode: ƒ encode(lat, lon, precision) //HERE IS MY FUNCTION
length: 0
name: "Geohash"
neighbours: ƒ neighbours(geohash)
prototype: {constructor: ƒ}
__proto__: ƒ ()
[[FunctionLocation]]: latlon-geohash.js:11
[[Scopes]]: Scopes[3]
Symbol(Symbol.toStringTag): "Module"
__esModule: true
__proto__: Object
我在那里看到了我的encode 函数。为什么它不起作用?我似乎找不到答案,但我觉得我可能缺少一些非常简单的东西。有什么想法吗?
【问题讨论】:
-
你应该将它添加到 angular.json 中的
scripts数组中。 -
但是我用
npm install latlon-geohash安装了它。我还需要在那里添加它吗? -
是的,从Node_modules添加整个路径
标签: javascript node.js angular typescript ecmascript-6