0

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

1 Answer 1

3
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);
};
Sign up to request clarification or add additional context in comments.

2 Comments

There's too much any, and there's no need for options variable. But otherwise yes, that's how it's done.
Thanks! Dont I have to use IComponentOptions in any way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.