0

我已经以 CJS 格式编写了我的 angularjs 应用程序,并将gulp-systemjs-builder它们捆绑到一个文件中。

我正在尝试将输出传递给 DI,但它失败了,因为 systemjs-builder 在和函数声明gulp-ng-annotate之间插入了几行。\* @ngInject *\

例子:

捆绑前:

/* @ngInject */ 
function ReportCtrl($scope) {
    var _ctrl = this;
}

捆绑后:

/* @ngInject */ 
var global = this || self,
    GLOBAL = global;
function ReportCtrl($scope) {
    var _ctrl = this;
}

谁能建议我如何解决这个问题?

4

1 回答 1

0

在https://github.com/olov/ng-annotate中找到了解决方案

/* @ngInject */我不得不使用 string"ngInject";作为函数声明后的第一行,而不是使用 comment 。这种方式gulp-systemjs-builder不会弄乱排序并且ng-annotate可以成功地注释功能。

所以不要写这个 -

/* @ngInject */ 
function ReportCtrl($scope) {
    var _ctrl = this;
}

我不得不写这个——

function ReportCtrl($scope) {
    "ngInject";
    var _ctrl = this;
}
于 2017-04-27T04:21:47.160 回答