how to fix Angular not using explicit annotation and cannot be invoked in strict mode

From the documentation it looks like you need to declare all dependency injections in string array.

There are other ways but normally I would do it like this:

controller: ['$scope', '$element', '$attrs', 'mouseCapture',
  function($scope, $element, $attrs, mouseCapture) {
    ...
  }
]

One of the reason we do this is because when we try to minify this js file, variable names would be reduced to one or 2 characters, and DI needs the exact name to find the services. By declaring DI in a string array, angular can match services with their minified variable name. For this reason, the string array and the function arguments need EXACT MATCHING in number and order.


Update:

If you are following John Papa's Angular style guide, you should do it like this:

controller: MouseCaptureController,
...

MouseCaptureController.$inject = ['$scope', '$element', '$attrs', 'mouseCapture'];

function MouseCaptureController($scope, $element, $attrs, mouseCapture) {
  ...
}

The code says:

$injector:strictdi

There is an error with the dependency injection In the documentation for this error:

Strict mode throws an error whenever a service tries to use implicit annotations

You should try to switching to:

.factory('mouseCapture', ['$rootScope', function ($rootScope) {...}]);

syntax, whenever in strict mode.


Just add 'ngInject' to the first line of your constructor.