2
votes

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) {...}
}
2

2 Answers

1
votes

It is under the auto module and it will be typed as IInjectorService

You can use it like this:

class TestCtrl {
  myReference: any;
  constructor($injector: ng.auto.IInjectorService){
    myReference = $injector.get('name');
  }
}
1
votes

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 was new when angular definitions were written and due to the popularity of angular we haven't had the opportunity to refactor it into a better one.