我在缩小时会遇到奇怪的错误,我怀疑这与我在指令中有控制器的事实有关:
var app = angular.module('myapp');
app.directive("person", ['$dialog', function($dialog) {
return {
restrict: "E",
templateUrl: "person/views/person.html",
replace: true,
scope: {
myPerson: '='
},
controller: mycontroller
};
function mycontroller($scope, $attrs) {
$scope.variable = 1;
}
}]);
重构这个的正确方法是什么,以便在小型化过程中不会被破坏?
答案 0 :(得分:1)
如果你想这样写,你必须使用$inject
mycontroller.$inject = ['$scope', '$attrs'];
参考:https://github.com/johnpapa/angularjs-styleguide#style-y075
但我会说你不要使用这些"模仿友好"依赖注入风格,并查看将为您执行此操作的自动化工具 - ng-annotate (或可在构建中使用的gulp / grunt派生词。)