简体   繁体   English

在angular中找不到命名空间

[英]Cannot find namespace in angular

Following this: => https://cesium.com/blog/2018/03/12/cesium-and-angular/ 在此之后:=> https://cesium.com/blog/2018/03/12/cesium-and-angular/

I have a global var in my typing.d.ts => 我在打字时有一个全局变量.d.ts =>

declare var Cesium;

my tsConfig contain => 我的tsConfig包含=>

"typeRoots": [
  "node_modules/@types",
  "./src/typings.d.ts"
],

Now, In my directive, I have the following 现在,在我的指令中,我有以下内容

import { Directive, ElementRef, OnInit, Input, Output} from '@angular/core';
import * as CesiumLib from '../libs/cesium.lib';

@Directive({
  selector: '[appCesium]'
})
export class CesiumDirective implements OnInit {
  @Input() appCesiumOptions: CesiumLib.CesiumViewerOptions;
  @Output() appCesiumViewer: Cesium.Viewer;

  constructor(private el: ElementRef) {
    Cesium.Ion.defaultAccessToken = CesiumLib.CESIUM_ACCESS_TOKEN;
  }

  ngOnInit() {
    const appCesiumViewer = new Cesium.Viewer(this.el.nativeElement, this.appCesiumOptions);
  }
}

the line 线

const appCesiumViewer = new Cesium.Viewer

work ok and without error, but the line 工作正常,没有错误,但行

@Output() appCesiumViewer: Cesium.Viewer;

give me the following 给我以下

Cannot find namespace 'Cesium'. 找不到名称空间“ Cesium”。

I also try to make a structure, but I have the same error 我也尝试做一个结构,但是我有同样的错误

what am I doing wrong? 我究竟做错了什么?

导出声明的模块

export declare var Cesium;

The following worked for me. 以下对我有用。

First, install package for example moment. 首先,以安装软件包为例。

npm install moment --save

Then, to work around the lack of a proper export: 然后,要解决缺少适当的出口的问题:

import * as moment from 'moment'; 从“时刻”开始输入*;

Note: import * as moment from 'moment'; 注意: import * as moment from 'moment'; format is important 格式很重要

import * as aliasname from 'packagename';

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

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