简体   繁体   English

使用JsDoc3创建AngularJS文档的问题

[英]Issues creating AngularJS documentation using JsDoc3

I have an AngularJS factory that I am trying to generate documentation for using Jsdoc. 我有一个AngularJS工厂,我正在尝试生成有关使用Jsdoc的文档。 The logic is below: 逻辑如下:

(function (angular) {

    /**
    * @module factories
    * @memberOf angular_module
    */
    var factories = angular.module('factories');

    /**
    * @class BaseService
    * @classdesc Base object
    * @param {Object} $rootScope Root scope for the application.
    */
    factories.factory('BaseService', ['$rootScope', function ($rootScope) {

        var baseObject = (function () {

            // Prototype
            var basePrototype = {

                _construct: function (args) {

                },

                publicMethod: function (args) {                    

                }
            };

            // 'Private' methods
            function initialise(args) {

            }

            function privateMethod(param) {

            }

            function setObjectProperties(o, properties) {
                for (prop in properties) {
                    if (properties.hasOwnProperty(prop)) {
                        o[prop] = properties[prop];
                    }
                }
            }

            //-----------------------------------------------
            return {
                create: function (args, properties) {
                    function obj() { }
                    obj.prototype = basePrototype;
                    var o = new obj();

                    setObjectProperties(o, properties);

                    // Call the base object 'constructor'
                    o._construct(args);              
                    return o;
                }
            };
        })();

        return  {

            /**
            * @function create
            * @memberof! BaseService
            * @description Creates a new object
            */
            create: function (args, properties) {
                return baseObject.create(args, properties);
            }
        };
    }
    ]);

    /** 
    * @class ChildService
    * @classdesc Child object
    * @extends BaseService
    */
    factories.factory('ChildService', ['BaseService', function (BaseService) {
        return BaseService.create({ 'someProperty': true }, {
            /**
            * @function childPublicMethod
            * @description Child public method
            */
            childPublicMethod: function () {
                return this.publicMethod(123);
            }
        });
    }]);

}(angular));

In another file I have: 在另一个文件中,我有:

/**
* @namespace angular_module
*/

The problem I am having is I would like to generate documentation for the BaseService.create method as part of the BaseService documentation. 我遇到的问题是,我想为BaseService.create方法生成文档,作为BaseService文档的一部分。 Similarly I would like to generate documentation for the ChildService.childPublicMethod function in the ChildService section. 同样,我想在ChildService部分为ChildService.childPublicMethod函数生成文档。 However currently nothing is created for BaseService.create, and the documentation for ChildService.childPublicMethod is added to the factories module. 但是,当前没有为BaseService.create创建任何内容,并且将ChildService.childPublicMethod的文档添加到了factorys模块中。 I have tried using @lends and @alias, as well as all sorts of combinations of modules/class names as part of the @memberof line, but nothing thus far has given me the desired outcome. 我已经尝试使用@lends和@alias以及模块/类名的各种组合,作为@memberof行的一部分,但是到目前为止,没有任何东西给我期望的结果。 Any suggestions gratefully received. 任何建议表示感谢。

The solution I have come up with is as follows: 我提出的解决方案如下:

(function (angular) {

    /** 
    * @namespace factories
    * @memberof angular_module
    */
    var factories = angular.module('factories');

    /**
    * @class BaseService
    * @classdesc Base object
    * @param {Object} $rootScope Root scope for the application.
    * @memberof angular_module.factories
    */
    factories.factory('BaseService', ['$rootScope', function ($rootScope) {
        var baseObject = (function () {

            // Prototype
            var basePrototype = {

                _construct: function (config) {

                },

                /**
                * @function publicMethod
                * @description Creates a new object
                * @memberof angular_module.factories.BaseService
                */
                publicMethod: function (args) {                    

                }
            };

            // 'Private' methods
            function initialise(args) {

            }

            function privateMethod(param) {

            }

            function setObjectProperties(o, properties) {
                for (prop in properties) {
                    if (properties.hasOwnProperty(prop)) {
                        o[prop] = properties[prop];
                    }
                }
            }


            //-----------------------------------------------
            return {
                create: function (args, properties) {
                    function obj() { }
                    obj.prototype = basePrototype;
                    var o = new obj();

                    setObjectProperties(o, properties);

                    // Call the base object 'constructor'
                    o._construct(args);              
                    return o;
                }
            };
        })();

        return  {
            /**
            * @function create
            * @description Creates a new object
            * @memberof angular_module.factories.BaseService
            */
            create: function (args, properties) {
                return baseObject.create(args, properties);
            }
        };
    }
    ]);

    /** 
    * @class ChildService
    * @classdesc Child object
    * @memberof angular_module.factories
    * @extends angular_module.factories.BaseService
    */
    factories.factory('ChildService', ['BaseService', function (BaseService) {
        return BaseService.create({ 'someProperty': true }, {
            /**
            * @function childPublicMethod
            * @description Child public method
            * @memberof ChildService
            */
            childPublicMethod: function () {
                return this.publicMethod(123);
            }
        });
    }]);

}(angular));

Here's the changes: 这是更改:

  1. I replaced the @module declaration for the 'factories' variable with @namespace 我用@namespace替换了'factories'变量的@module声明

  2. I added @memberof angular_module.factories to the class declarations. 我在类声明中添加了@memberof angular_module.factories。

  3. I prefaced the values for the @extends and @memberof tags with angular_module.factories. 我以angular_module.factories为@extends和@memberof标签的值添加了前缀。

Really hope this helps someone out. 真的希望这可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM