Solution to this issue is to assign function to a scope variable using arrow method.
interface IHomeControllerScope extends ng.IScope {
GetEmployee: (id) => ng.IPromise<Model.Employee>;
}
interface IHomeController {
Employee: any;
}
class HomeController implements IHomeController {
static controllerId: string = "HomeController";
Employee = this.$resource("api/employee/:Id", { Id: '@id' });
constructor(
private $scope: IHomeControllerScope,
private $http: ng.IHttpService,
private $resource: ng.resource.IResourceService,
private $log: ng.ILogService,
private $q: ng.IQService) {
**$scope.GetEmployee = () => this.GetEmployee ;**
}
GetEmployee(id) {
var defer = this.$q.defer<Model.Employee>();
this.Employee.get({ Id: id },
(result) => {
this.log.debug(result);
defer.resolve(result);
}, (result) => {
defer.reject(result);
});
return defer.promise;
}
}
app.controller(HomeController.controllerId, ['$scope', '$http', '$resource', '$log', '$q', ($scope, $http, $resource, $log, $q) =>
new HomeController($scope, $http, $resource, $log, $q)
]);
This will generate required syntax for your controllers.