我试图将此指令转换为typescript中的组件。我看过几个关于如何操作的视频和文章,但大多数都是用javascript编写的,所以有点不清楚。
以下是代码:
export class TableRowBSGroupDirective implements ng.IDirective {
restrict: string = 'A';
scope: any = {
dirvm: '=',
grouplvl: '=',
classlvl: '@'
};
templateUrl: any = balanceSheetFSPolicy.dirvmConstant.TableRowGroupTmpl;
controller: any = ($scope: any) => {
balanceSheetFSPolicy.balanceSheetFSViewModel = $scope.dirvm;
$scope.balanceSheetFSPolicy = balanceSheetFSPolicy;
};
static factory(): ng.IDirectiveFactory {
const directive = function () {
return new TableRowBSGroupDirective();
};
return directive;
}
}
angular
.module('app.recon.statements')
.directive('tableRowBsGroup', TableRowBSGroupDirective.factory());
答案 0 :(得分:2)
export class TableRowBSGroupCtrl {
// Dependency Injection
static $inject: [string] = [
'$scope'
// Apply all the dependancies for the component here
// $scope as an example
];
// Access Bindings
protected dirvm: any;
protected grouplvl: any;
protected classlvl: any;
constructor(private $scope: ng.IScope) {
// Place the Logics here which are in the controller function in your directive
}
public static factory() {
// Here goes your static function body
}
}
const options = {
templateUrl: //the path for the template,
bindings: {
dirvm: '=',
grouplvl: '=',
classlvl: '@'
},
controller: TableRowBSGroupCtrl
};
export default (ngModule: any) => {
ngModule.component('TableRowBSGroupCmp', options);
};