我在缩小时遇到奇怪的错误,我怀疑这与我在指令中具有控制器的事实有关:
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;
}
}]);
重构它的正确方法是什么,以使其在微型化过程中不会损坏?
如果要这样写,则必须使用 $inject
mycontroller.$inject = ['$scope', '$attrs'];
参考:https : //github.com/johnpapa/angularjs-styleguide#style-y075
但我会建议您不要使用这种“最小化友好”依赖项注入样式,而是使用自动工具为您执行此操作-ng-annotate(或可以在您的构建中使用的gulp / grunt派生类)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句