Given an angular app with a factory that returns a class, as such:
angular.module('fooApp').factory('User', function(){
function User(name){
this.name = name;
}
User.prototype.greet = function(){
return "Howdy, " + this.name;
}
return User;
});
Using ngdoc
(the special flavor of jsdoc
angular uses), how do I document the initializer without defining it as a method?
Right now, this is what I've tried:
/**
* @ngdoc service
* @name fooApp.User
* @description User factory.
*/
angular.module('fooApp').factory('User', function(){
/**
* @ngdoc method
* @methodOf fooApp.User
* @name Initializer
* @description Initializes a new User object with a name
*/
function User(name){
this.name = name;
}
User.prototype.greet = function(){
return "Howdy, " + this.name;
}
return User;
});
But this results in the User
initializer (the User
function that accepts the parameter name
) being treated like a method with the name Initializer
, which is confusing to people trying to use this code.
I've tried adding the @constructor
flag, but this has no effect of the html .dgeni
ends up generating
Thank you.
UPDATE: Removed references to dgeni
. I was under the impression that the plugin I was using (grunt-ngdocs) uses dgeni
behind the scenes, but this is not the case.
This is how I would do it not having any experience with Angular in particular:
/**
* @ngdoc service
* @name fooApp.User
* @description User factory.
*/
angular.module('fooApp').factory('User', function(){
/**
* @ngdoc method
* @constructs fooApp.User
* @description Initializes a new User object with a name
*/
function User(name){
this.name = name;
}
User.prototype.greet = function(){
return "Howdy, " + this.name;
}
return User;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With