【问题标题】:Using @types/angular as global使用 @types/angular 作为全局
【发布时间】:2017-04-06 01:58:31
【问题描述】:

我目前正在尝试将我的 angular 1 应用程序从 typings 更新为 @types

首先我收到以下错误消息:

Identifier 'angular' must be imported from a module

经过一番搜索,我发现,该 angular 不再可以在全球范围内访问。或者至少我没有发现如何......


有了typingsangular 是全局的,我可以在没有导入或任何东西的情况下使用它。我的问题是,一个角度的导入,像这样:

import * as angular from 'angular';

破坏了我的应用程序:不幸的是,SystemJS 现在正在尝试加载角度,因此当ui-bootstrap 和其他库加载了脚本标签时,它不可用。

要解决这个问题,我必须重写大部分构建管道。所以我再次问:有没有另一种方法可以使用 TypeScript 2@types 的角度,而不是以 require('angular') 结尾?

【问题讨论】:

  • 现在有同样的问题。你找到解决办法了吗?

标签: angularjs typescript typescript-typings


【解决方案1】:

我找到了答案。这样做,一切都会好起来的。

import * as _angular_ from 'angular';

declare global {
  const angular: typeof _angular_;
}

【讨论】:

    猜你喜欢
    • 2017-04-01
    • 2019-04-01
    • 2020-02-06
    • 2018-11-17
    • 2021-05-24
    • 2017-09-04
    • 1970-01-01
    • 2019-11-23
    • 2018-04-20
    相关资源
    最近更新 更多