[英]Converting directive to a component in typescript
Im trying to convert this directive into a component in typescript. 我试图将此指令转换为打字稿中的组件。 I saw a couple of videos and articles on how to do so, but most of them are in javascript so it is a bit unclear.
我看到了一些有关如何执行此操作的视频和文章,但是其中大多数都是使用javascript编写的,因此不清楚。
Here is the code: 这是代码:
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());
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);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.