I have an angular module and service that was developed without typescript such as:
MyModule = angular.module('MyModule', ['dependency1', 'dependency2']);
MyModule.factory('MyService', ['$otherDependency', function ($otherDependency) {
return {
myOperation: function(){...}
};
}]);
I want to use this service in a typescript class without converting everything else to typescript. I tried the following but the injected service is always null:
/// <reference path="angular.d.ts"/>
module MyTypescriptModule {
export class MyClass extends MyOtherClass {
static $inject = ['MyService'];
constructor(private MyService) { ... }
}
}
Is this possible, and if so what am I missing?
UPDATE: I was able to use PSL's suggestion from his js bin, slightly modified to avoid a dependency error with help from this question: Call Angular JS from legacy code
var angularInjector = angular.element($("#divWithNgApp")).injector();
MyService = angularInjector.get('MyService');