如何使用打字稿的ES6模块语法来导入angular.IInjectorService [英] How to import angular.IInjectorService using the ES6 module syntax in TypeScript
问题描述
我如何导入angular.IInjectorService从角。使用ES6模块语法d.ts 文件中打字稿的?
编辑:我很想知道的是我怎么可以使用 IInjectorService
没有完全限定它。换句话说,我想这样做:
类TestCtrl {
构造函数($喷油器:IInjectorService){...}
}
而不是这样的:
类TestCtrl {
构造函数($喷油器:ng.auto.IInjectorService){...}
}
目前,我正在做内部模块的方式。事情是这样的:
///<参考路径=../路径/要/类型定义/ angularjs /角/>进口IInjectorService = ng.auto.IInjectorService;类TestCtrl {
构造函数($喷油器:IInjectorService){...}
}
我的问题是,是否有ES6的方式来做到这一点?例如,像下面的伪code:
进口{} IInjectorService../path/to/typeDefinitions/angularjs/angular';类TestCtrl {
构造函数($喷油器:IInjectorService){...}
}
下面的工作:
从角进口{自动为ngAuto};
VAR富:ngAuto.IInjectorService;
不过,我想说,汽车
是一个贫穷的决定(但话又说回来所以是 I
preFIX)。打字稿我们新角时被DEFS书面和因角度普及,我们还没有机会把它重构为一个更好的画质。
How do I import the angular.IInjectorService from the angular.d.ts file using the ES6 module syntax in TypeScript?
EDIT: What I'd really like to know is how I can use the IInjectorService
without fully qualifying it. In other words, I want to do this:
class TestCtrl {
constructor($injector: IInjectorService) {...}
}
Instead of this:
class TestCtrl {
constructor($injector: ng.auto.IInjectorService) {...}
}
Currently, I'm doing it the internal module way. Something like this:
///<reference path="../path/to/typeDefinitions/angularjs/angular" />
import IInjectorService = ng.auto.IInjectorService;
class TestCtrl {
constructor($injector: IInjectorService) {...}
}
My question is, is there an ES6 way to accomplish this? For example, something like the following pseudocode:
import {IInjectorService} from '../path/to/typeDefinitions/angularjs/angular';
class TestCtrl {
constructor($injector: IInjectorService) {...}
}
The following will work:
import {auto as ngAuto} from "angular";
var foo:ngAuto.IInjectorService;
However I'd like to say that auto
was a poor decision (but then again so was the I
prefix). TypeScript we new when angular defs were written and due to popularity of angular we haven't had the opportunity to refactor it into a better def.
这篇关于如何使用打字稿的ES6模块语法来导入angular.IInjectorService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!