angularjs – 未调用Angular Typescript Controller构造函数

我正在使用Angular类型脚本.

我在类型脚本中有模型类

module app.form {

    export class Patient{

        constructor(
            public firstName: string,
            public lastName: string,
            public gender: string,
            public birthDate: Date,
            public currentMedications: string,
            public notes: string,
            public isMedicare: boolean,
            public medicareName: string,
            public medications: string[],
            public ethnicity: string[],
            public billingInfo: BillingInformation,
            public specimenInfo: SpecimenInformation,
            public assayRequested: AssayRequested,
            public authorizationDetail: AuthorizationDetail
        ) {

        }
    }
}

使用类型脚本的我的Controller代码是这样的

module app.form {
    export class MainController {
        constructor(public patient: Patient) {

        } 
    }   
}

我的app文件看起来像这样.

module app.form {
    angular
        .module("formApp", [
            "ngMaterial",
            "ngMdIcons",
            "ngMessages"
        ])
        .controller("MainController", MainController);
}

我按此顺序在html文件中注册所有脚本

<script src="Scripts/angular.min.js"></script>
    <script src="Scripts/angular-resource.min.js"></script>
    <script src="Scripts/angular-animate/angular-animate.min.js"></script>
    <script src="Scripts/angular-aria/angular-aria.min.js"></script>
    <script src="Scripts/angular-messages.min.js"></script>
    <script src="Scripts/angular-material/angular-material.min.js"></script>
    <script src="Scripts/angular-material-icons/angular-material-icons.min.js"></script>

    <script src="app/model.js"></script>
    <script src="app/controllers/main-controller.js"></script>
    <script src="app/app.js"></script>

当我运行我的应用程序时,我看到这个错误

《angularjs – 未调用Angular Typescript Controller构造函数》

我在哪里做错了?

最佳答案 要解决错误,必须在使用typescript时在控制器中使用静态$inject

static $inject = [];
点赞