Я пытаюсь перенести AngularJS на типизацию.Я столкнулся со странной проблемой, что testController не определен, если я определяю инъекции со статическим $ inject, как показано ниже.
Контроллер TS
class TestController {
private customerName : string;
private customerLink : string;
private contactDetails : any;
private userPosts : any;
static $inject = ["TestService", "CustomerContactService"];
constructor(private TestService: ITestService, private CustomerContactService: any) {
console.log("inside constructor TestController");
}
init(customerName, customerLink) {
if(customerName && customerLink) {
this.customerName = TestConstant.HELLO + customerName;
this.customerLink = customerLink;
}
}
getPosts() {
this.testService.getUserPosts().then((response : ng.IHttpPromiseCallbackArg<any>) =>{
this.userPosts = JSON.stringify(response.data);
});
}
getContactDetails() {
this.customerContactService.getContacts("sales").then((response : ng.IHttpPromiseCallbackArg<any>) =>{
this.contactDetails = JSON.stringify(response);
});
}
}
angular
.module("testModule")
.controller("testController", TestController);
Служба TS
interface ITestService {
getUserPosts() : ng.IPromise<ng.IHttpPromiseCallbackArg<any>>;
}
class TestService implements ITestService {
static $inject = ['$http'];
constructor(private $http : ng.IHttpService) {
}
getUserPosts() : ng.IPromise<ng.IHttpPromiseCallbackArg<any>> {
return this.$http.get("https://jsonplaceholder.typicode.com/posts/1");
}
}
angular
.module("testModule")
.service("testService", TestService);
Однако , если я использую следующее в моем контроллере
static AngularDependencies = ["TestService", "CustomerContactService"];
OR
static helloWorld = ["TestService", "CustomerContactService"];
все работает нормально.Что я делаю неправильно?и как мне использовать static $ inject, поскольку это выглядит как соглашение?
Ошибка: [ng: areq] http://errors.angularjs.org/1.3.15/ng/areq?p0=testController&p1=not%20a%20function%2C%20got%20undefined
TIA