radioaktiv radioaktiv - 25 days ago 12
AngularJS Question

Module 'ng' has no exported member 'IDirective'

I am implemeting Angular 1 directive with TypeScript. Everything looks fine, it compiles, but I receive the following error in my Visual Studio Code editor:


Module 'ng' has no exported member 'IDirectiveFactory'.


Here is my code:

class MyDirective implements ng.IDirective {

constructor(a, b) {
......
}

static factory(): ng.IDirectiveFactory {
const directive = (a, b) => new MyDirective(a, b);
directive.$inject = ['a', 'b'];
return directive;
}

///more code
};

angular.module('module1').directive('mydirective', MyDirective.factory());


I tried to replace
ng.IDirectiveFactory
with
angular.IDirectiveFactory
, and that worked fine but the documentation says I should use the
ng
module instead of the
angular
one.

Any ideas ?

Answer

I guess you're importing angular this way:

import * as angular from 'angular';

They probably import it in the documentation like this:

import * as ng from 'angular';

They do it because it's shorter :).