解释为服务的简单类型脚本构造函数变量(带有类型脚本的AngularJS)

解释为服务的简单类型脚本构造函数变量(带有类型脚本的AngularJS),angularjs,typescript,Angularjs,Typescript,我用TypeScript设置了一个简单的控制器和接口 module signup { // define signup interface for signup home controller interface ISignupCredentials { firstName: string; companyEmail: string; password: string; } export class Signu

我用TypeScript设置了一个简单的控制器和接口

module signup { 

    // define signup interface for signup home controller
    interface ISignupCredentials {
        firstName: string;
        companyEmail: string;
        password: string;
    }

    export class SignupCtrl implements ISignupCredentials {

        static IID = "SignupCtrl";          
        constructor(public firstName: string,
                    public companyEmail: string,
                    public password: string) {                      

                    }                   
    }

    angular
        .module("signup", [])
        .controller(SignupCtrl.IID, SignupCtrl)     

}
我得到了这个错误:


看起来我认为这些是服务,但我不知道为什么。我完全错过了一些东西,但我看不出是什么。任何帮助都将不胜感激!谢谢。

问题在于控制器构造方法确实定义了服务,因为它是由Angular调用的,并传递了必要的依赖项。您不需要手动构造控制器实例

适当的接口实施将是:

// define signup interface for signup home controller
interface ISignupCredentials {
    firstName: string;
    companyEmail: string;
    password: string;
}

export class SignupCtrl implements ISignupCredentials {

    static IID = "SignupCtrl";

    firstName: string;
    companyEmail: string;
    password: string;

    constructor() {
        // ...
    }
}

angular
    .module("signup", [])
    .controller(SignupCtrl.IID, SignupCtrl)

可能是因为您没有导出该模块?尝试导出模块注册,甚至删除该行。太好了,这很有效!谢谢你的解释:)