如何使用打字稿的ES6模块语法来导入angular.IInjectorService [英] How to import angular.IInjectorService using the ES6 module syntax in TypeScript

查看:273
本文介绍了如何使用打字稿的ES6模块语法来导入angular.IInjectorService的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何导入angular.IInjectorService从角。使用ES6模块语法d.ts 文件中打字稿的?

编辑:我很想知道的是我怎么可以使用 IInjectorService 没有完全限定它。换句话说,我想这样做:

 类TestCtrl {
    构造函数($喷油器:I​​InjectorService){...}
}

而不是这样的:

 类TestCtrl {
    构造函数($喷油器:ng.auto.IInjectorService){...}
}

目前,我正在做内部模块的方式。事情是这样的:

  ///<参考路径=../路径/要/类型定义/ angularjs /角/>进口IInjectorService = ng.auto.IInjectorService;类TestCtrl {
    构造函数($喷油器:I​​InjectorService){...}
}

我的问题是,是否有ES6的方式来做到这一点?例如,像下面的伪code:

 进口{} IInjectorService../path/to/typeDefinitions/angularjs/angular';类TestCtrl {
    构造函数($喷油器:I​​InjectorService){...}
}


解决方案

下面的工作:

 从角进口{自动为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆