Class-level injectable dependencies in Angular 1.x using TypeScript?

后端 未结 1 1335
情歌与酒
情歌与酒 2021-01-14 08:12

Sorry for the somewhat convoluted title.

I have been using Angular 1.x for a couple years now and have recently been investigating the potential of using TypeScript

相关标签:
1条回答
  • 2021-01-14 09:03

    I believe it should be treated in Typescript in similar manner like it would be in ES7:

    class BaseClass {
    
        static $inject = ['$http'];
    
        constructor(...args) {
            (<any>this).constructor.$inject.forEach((service, index) => {
                this[service] = args[index];
            });
        }
    }
    

    This way children may inherit dependencies or have their own by calling super().

    0 讨论(0)
提交回复
热议问题