Error: $injector:unpr in angular injector().invoke after grunt or gulf minify

Sometimes we need to inject and compile some markup using $compile service from outside AngularJs.
We can do this using the extra injector() added to JQuery/jqLite elements. Like this:

angular.element(document).injector().invoke(function($compile) {
  var scope = angular.element($div).scope();

And you are receiving an error like- Uncaught Error: [$injector:unpr]$injector/unpr?xxxx

The reason behind this is that minification changes $compile into random variable that doesn’t tell angular what to inject.

You can avoide this error by declaring your dependencies like this:

 angular.element(document).injector().invoke(['$compile', function($compile) {
    var scope = angular.element($div).scope();

That should fix your problem.