After upgrading TypeScript, Angular controller registration now fails to compile

后端 未结 3 616
夕颜
夕颜 2021-02-01 02:10

We were using TypeScript 2.2. After upgrading to 2.4, we now get this on compilation:

error TS2345: Argument of type \'typeof TopMenuController\' is not

3条回答
  •  再見小時候
    2021-02-01 02:40

    I also faced the same issue which I got resolved by

    • implementing IController

    • add this code before constructor (or anywhere in code this is my preference) $onInit = () => { };

    here is the full code, Hope this will give a clear view

    module MyApp {
        export class HomeController implements angular.IController {
            $onInit = () => { };
            user: string;
            constructor() {
                this.user = "mali";
            }
        }
        angular.module('app').controller('homeController', MyApp.HomeController)
    }
    

    Happy Coding

提交回复
热议问题