If I have the following:
myapp.directive('directivename', ...
return {
...
restrict: 'E',
controller: MyController,
...
}
function MyController($scope, $somethingelse) {
// Contents of controller here
}
);
How do I modify this such that MyController
will not get destroyed when minified?
I am getting the following error:
Error: [$injector:unpr] Unknown provider: eProvider <- e
Usually, the following approach is used:
to avoid such problems.
You can use like this:
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.Or in the directive:
Or register your controller using
.controller
syntaxand set up controller name in the directive instead of the constructor.
You can also take a look at ng-annotate with which you don't need to use explicit annotation.