AngularJS + 提供商 + Webpack

AngularJS + Provider + Webpack

有一个angularjs应用程序是由webpack构建的(它在构建时也使用了babel-loader)。

有一个 MessageProvider.js 文件,代码如下:

const SERVER_SIDE_MESSAGE_PROVIDER = ['$injector', ($injector) => {

var localeJson = [];

this.loadLocale = (lang) => {
    ....
};

this.$get = () => {
    return {
        ....
    };
};
}];
export { SERVER_SIDE_MESSAGE_PROVIDER };

使用 webpack 成功构建应用 后,浏览器中显示错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module *app name* due to:
TypeError: Cannot set property 'loadLocale' of undefined

指向行

this.loadLocale = (lang) => ....

你能告诉我如何解决这个问题吗?

像这样:

function($injector) {

箭头函数上没有this