1

I have a simple controller and interface set up with 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)     

}

I'm getting this error:

enter image description here

It looks like Angular thinks these are services, but I'm not sure why. I'm missing something completely here, but I can't see what it is. Any help would be appreciated! Thanks.

1
  • Could it be that you're not exporting that module? Try export module signup or even just remove that line. Commented Dec 20, 2015 at 22:02

1 Answer 1

1

The problem is that controller construct method is indeed defines services, because it's called by Angular with necessary dependencies passed in. You don't construct controller instances manually.

Proper interface implementation would be:

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

1 Comment

Perfect, this worked! Thank you for the explanation :)

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.