本文介绍了使用指令控制器进行角度缩小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有以下几点:

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:

错误:[$injector:unpr] 未知提供者:eProvider

推荐答案

可以通过使用显式依赖注解来解决.您拥有的隐式注释会在缩小时导致问题.您也可以使用 $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 语法注册你的控制器

Or register your controller using .controller syntax

app.controller('MyController', ['$scope', '$somethingelse', MyController]);

并在指令中设置控制器名称而不是构造函数.

and set up controller name in the directive instead of the constructor.

return {
    ...
    restrict: 'E',
    controller: 'MyController',
    ...
}

您还可以查看 ng-annotate需要使用显式注释.

You can also take a look at ng-annotate with which you don't need to use explicit annotation.

这篇关于使用指令控制器进行角度缩小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 19:24