问题描述
如果我有以下内容:
myapp.directive('directivename', ...
return {
...
restrict: 'E',
controller: MyController,
...
}
function MyController($scope, $somethingelse) {
// Contents of controller here
}
);
如何修改这个 MyController
缩小时不会被摧毁?
我收到以下错误:
How do I modify this such that MyController
will not get destroyed when minified?I am getting the following error:
推荐答案
可以使用显式依赖注释来解决它。你有什么隐含的注释,在缩小时会导致问题。您也可以使用 $ inject
或内联数组注释来注释指令中的依赖项。
It can be resolved by using explicit dependency annotation. What you have it implicit annotation which causes issues while minification. You could use $inject
or inline array annotation to annotate the dependencies in the directive as well.
MyController.$inject = ['$scope', '$somethingelse'];
function MyController($scope, $somethingelse) {
// Contents of controller here
}
或者在指令中:
return {
...
restrict: 'E',
controller: ['$scope', '$somethingelse', MyController],
...
}
或者使用 .controller注册你的控制器
语法
app.controller('MyController', ['$scope', '$somethingelse', MyController]);
并在指令中设置控制器名称而不是构造函数。
and set up controller name in the directive instead of the constructor.
return {
...
restrict: 'E',
controller: 'MyController',
...
}
您还可以查看 ,您不需要使用显式注释。
You can also take a look at ng-annotate with which you don't need to use explicit annotation.
这篇关于使用指令控制器进行角度缩小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!