导入不同名称的包装类型

时间:2017-09-17 11:02:43

标签: angularjs typescript webpack typescript2.0 ng-idle

我正在将现有项目转换为打字稿。该项目正在使用包ng-idle,它包含名称为angular-idle的@types包,文件@types/angular-idle/index.d.ts包含

declare module 'angular' {
    export namespace idle {
         ....

如何导入此包

   import * as ngIdle from 'angular-idle'

   import * as ngIdle from 'ng-idle'

1 个答案:

答案 0 :(得分:1)

有几种方法可以做到这一点

for (var i = 1; i < x2.length + 1; i++) {
    if (id != "perc" + i) {
      document.getElementById("perc" + i).value = parseFloat(sharePerc).toFixed(0);
      document.getElementById("val" + i).value = parseFloat(shareValue).toFixed(0);
    }
  }

您甚至可以在导入时重命名命名空间

import {idle} from 'angular'
const blah = idle.BLAH

如果您已导入角度

import {idle as ng_idle} from 'angular'
const blah = ng_idle.BLAH

(或直接使用 import * as angular from 'angular' import idle = angular.idle const blah = idle.BLAH