将Angular控制器函数移动到单独的Typescript类

时间:2017-04-26 12:29:29

标签: angularjs typescript

我正在使用AngularJS和Typescript处理应用程序。应用程序中添加了许多要求,因此我希望在代码失控之前确定结构。

我有一个1500行的Angular控制器,我想将这些函数移动到一个单独的文件中,如下所示:

export class CtrlFunctions{
    private scope: any;

    constructor($scope) {
        this.scope = $scope;
    }

    updateHeader = header => {
        //more logic here
        this.scope.header = header;
    }
}

我会像这样访问控制器中的值:

import { CtrlFunctions } from "../controller-functions/entry.ctrl.func";

namespace Entry {
    class EntryCtrl {
        private funcs: CtrlFunctions
        constructor(){
            this.funcs = new CtrlFunctions($scope);
        }
    }
}

这是不好的做法吗?有没有更好的方法来利用Typescript提供的模块性?

0 个答案:

没有答案
相关问题