I have a module and service in Angular that were originally developed without TypeScript, like this:
MyModule = angular.module('MyModule', ['dependency1', 'dependency2']);
MyModule.factory('MyService', ['$otherDependency', function ($otherDependency) {
return {
myOperation: function(){...}
};
}]);
Now, I want to incorporate this service into a TypeScript class without converting everything else. I attempted the following code, but the injected service always ends up being null:
/// <reference path="angular.d.ts"/>
module MyTypescriptModule {
export class MyClass extends MyOtherClass {
static $inject = ['MyService'];
constructor(private MyService) { ... }
}
}
Is there a way to achieve this, and if so, what am I overlooking?
UPDATE: I managed to implement PSL's suggestion from their js bin example, with slight modifications to avoid a dependency error, using guidance from this helpful question: Call Angular JS from legacy code
var angularInjector = angular.element($("#divWithNgApp")).injector();
MyService = angularInjector.get('MyService');