I am rewriting my AngularJS application using TypeScript. In my application I have used $scope to define variables and methods:
defectResource.defectByDefectId($scope.defectid).then(function (data) {
$scope.defect = data;
});
$scope.postDefect = function () {
defectResource.postDefect($scope.defect).then(function () {
$location.path('defects/' + $stateParams.itemid);
});
};
I can rewrite my controller something like this:
interface IDefectDetailModel {
}
class DefectDetailController implements IDefectDetailModel {
static $inject = ['$scope', '$stateParams', '$location', 'defectResource', 'entityProvider'];
constructor($scope: any, $stateParams: any, $location: any, defectResource: any, entityProvider: any) {
defectResource.defectByDefectId($scope.defectid).then(function (data) {
$scope.defect = data;
});
$scope.postDefect = function () {
defectResource.postDefect($scope.defect).then(function () {
$location.path('defects/' + $stateParams.itemid);
});
};
}
}
But if I understood correctly it is not good way. I need to create Interface and TypeScript class which will implement this interface. All my variables must be class variables (so $scope.defectid must be this.defectid) and all my $scope methods must be class methods (this.postDefect()).
Do I understood correctly? If I am using AngularJS with TypeScript the best way is not use $scope variables and methods and use only instance variables and methods (using this) ?