Search code examples
javascriptangularjsgrailsasset-pipelineannotate-asset-pipeline

angular-annotate-asset-pipeline not working at all in a Grails 2 project


I have a project in Grails 2.4.4 in which I also use AngularJS.

I've decided to use the Asset Pipeline Plugin along with AngularJs Annotate Asset-Pipeline. The first one for processing, minifying, etc the static assets(js,css, etc) and the second one for getting the myFunc.$inject = [...] "injection" in every function that requires it due to the injection dependency in which AngularJS relies on.

According to the doc of AngularJs Annotate Asset-Pipeline it should put the myFunc.$inject=[] when the war is going to be generated on my js files when required, but the true is different: it is not working at all (I do not see any $inject in the minified file and the app breaks due to the dependency injection widely discussed on SO (examples: Angularjs error Unknown provider and AngularJS Error: $injector:unpr Unknown Provider)

Below is the relevant code (if any other is required, please, let me know)

BuildConfig.groovy

compile "org.grails.plugins:asset-pipeline:1.9.9"
compile "org.grails.plugins:angular-annotate-asset-pipeline:2.4.1"

AngularJS controller (this is just an example)

angular
    .module('app', [])
    .controller('myCtrl', myCtrl);

/*@ngInject*/          // << --- did not work!
function myCtrl ($scope){

//I also used the "ngIngect"; alternative here and it did not work either!

    $scope.myVar = "sample text";
}

Solution

  • Short answer:

    Change the version of the dependency

    from this:

    compile "org.grails.plugins:angular-annotate-asset-pipeline:2.4.1"
    

    to this:

    compile "org.grails.plugins:angular-annotate-asset-pipeline:1.1.3"

    Long story

    After digging into the AngularJs Annotate Asset-Pipeline, and with the help provided by a friend I came to the conclusion that the author of this plugin just removed the logic inside it.

    This means that right now (May 25th, 20017) with the current version of this plugin (2.4.1) nobody will be able to use it as it was intended to be used.

    So, if anybody is experiencing this same issue should use instead version 1.1.3 which is the latest I was able to use successfully.