几个月来,我一直在开发angular,现在正在研究是否值得为我的开发转移到typescript。我遇到的一个问题是使用外部模块和注入服务时的重复。例如,我有这个(简化的)代码:

///<reference path="../../../../typings/tsd.d.ts" />

// imports for strong typing
import audioModel = require('app/plugins/audio/audio.model');

export class AudioController {

    public model: audioModel;

    static $inject = ['$scope', '$q', 'AudioModel'];
    constructor(protected $scope, protected $q, protected AudioModel:audioModel) {
        this.model = new AudioModel();
    }

}

AudioMod是一个在外部模块“Audio.Mask.ts”中定义的角度工厂,所以在我看来,我注入了两次-一次使用角度,再次使用Type Script导入来获得强类型。
在amd项目中,有没有更好的方法同时使用角度依赖注入和强类型?

最佳答案

在amd项目中使用角度依赖注入和强类型有更好的方法吗?
这是Angular1.x依赖注入的问题。角度模块系统独立于现有的传统浏览器模块系统(如amd)。
所以你需要进口两次。一次是打字,下一次是DI。

关于angularjs - Angular + TypeScript + AMD =复制?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32627930/

10-11 23:43