简体   繁体   中英

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.

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);
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM