3

We have been developing a big product with AngularJS and only recently tried to use use closure compiler for syntax checking with the help of jsdoc comments.

I ran into this problem and can't find any help online, including in SO.

Consider a model class written as a service, and using the class name as a type:

ourmodule.factory('OurModel', function() {
    /**
     * @constructor
     */
    var OurModel = function() {};

    return OurModel;
});

ourmodule.controller('Controller1', ['$scope', 'OurModel', function($scope, OurModel) {
    /**
     * @return {OurModel}
     */
    $scope.getNewModel = function () {
         return new OurModel();
    }
}]);

Closure compiler can't recognize 'OurModel'. What am I missing ?

1
  • I guess closure compiler can't guess that the OurModel that you inject to your controller is the same you declared in the factory, angularJS injection pattern make closure compiler useless in that case, I'm not sure there is a notation to declare the type of the arguments you receive in the controller to prevent that... Commented Apr 26, 2013 at 18:07

1 Answer 1

1

Closure compiler can't guess that the OurModel that you inject to your controller is the same you declared in the factory, angularJS injection pattern make closure compiler useless in that case.

If you declare OurModel in the parent scope, no warning:

var ourmodule = {
  factory: function(a, b){},
  controller: function(a, b){}
};
/**
* @constructor
*/
var OurModel = function(){};

ourmodule.controller('Controller1', ['$scope', function($scope) {
/**
* @return {OurModel}
*/
$scope.getNewModel = function () {
return new OurModel();
}
}]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.