簡體   English   中英

將指令轉換為打字稿中的組件

[英]Converting directive to a component in 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());
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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM