meg*_*ter 5 typescript angular-cli typescript-typings angular
我有项目angular-cli
〜根〜/ SRC/typings.json
{
"globalDevDependencies": {
"angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
},
"globalDependencies": {
"es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504",
"google.maps": "registry:dt/google.maps#3.20.0+20160914131659"
}
}
Run Code Online (Sandbox Code Playgroud)
〜根〜/分型/ index.d.ts
/// <reference path="globals/angular-protractor/index.d.ts" />
/// <reference path="globals/es6-shim/index.d.ts" />
/// <reference path="globals/google.maps/index.d.ts" />
/// <reference path="globals/hammerjs/index.d.ts" />
/// <reference path="globals/jasmine/index.d.ts" />
/// <reference path="globals/selenium-webdriver/index.d.ts" />
Run Code Online (Sandbox Code Playgroud)
〜根〜/ SRC/tsconfig.json
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types",
"../typings"
],
"files": [
"../typings/index.d.ts"
]
}
}
Run Code Online (Sandbox Code Playgroud)
运行服务后, 我在控制台中有错误消息
ERROR在[默认] F:~root~\src\app\ui\google-map\map-marker\map-marker.directive.ts:7:26
找不到命名空间'google'
和
ERROR在[默认] ~root~\src\app\trip-entry-page\trip-entry-page.component.ts:188:21
找不到名字'google'
〜根〜\ SRC \应用\ UI \谷歌地图\地图标记\地图marker.directive.ts:7:26
...
@Input() veyoMapMarker: google.maps.MarkerOptions
...
Run Code Online (Sandbox Code Playgroud)
〜根〜\ SRC \程序\跳闸入门页\跳闸入门page.component.ts:188:21
...
if (status === google.maps.DirectionsStatus.OK) {
...
Run Code Online (Sandbox Code Playgroud)
构建应用程序后正确工作
我如何解决此错误消息?
Ste*_*aul 24
有点迟到的响应,但我使用Angular CLI RC.0时遇到了类似的问题.
事实证明,我没有安装和导入打字,可以按如下方式进行:
npm install --save-dev @types/googlemaps
import {} from '@types/googlemaps';
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,我所做的是,我只是删除了这些
import { } from 'googlemaps';
declare var google: any;
Run Code Online (Sandbox Code Playgroud)
从我的 component.ts 并在我的 tsconfig.app.json 中添加 "types": [ "googlemaps" ] 。. 现在我的 tsconfig.app.json 看起来像这样。
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": [
"googlemaps"
]
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
它的工作完美。
| 归档时间: |
|
| 查看次数: |
12213 次 |
| 最近记录: |