问题 无法构建angularjs doc(不知道如何格式化@ngdoc:方法)


我有一些带有一些文档的服务,但是当我尝试使用grunt-ngdocs构建文档时,它失败了:

Warning: Don't know how to format @ngdoc: method Use --force to continue.

这是我想要做的

(function(angular) {
    'use strict';

    angular.module('services.base64', [])
    .factory(
            'Base64',
            [function() {

                /**
                 * @ngdoc service
                 * @name Base64
                 * @module services.base64
                 * @description Provides encoding a string into base64, and decode base64 to a string
                 */
                return {
                    /**
                     * @ngdoc method
                     * @name Base64#encode
                     * @param {string}
                     *            input the string you want to encode as base64
                     * @returns {string} the base64 encoded string
                     */
                    encode : function(input) {
                        //...
                    },

                    /**
                     * @ngdoc method
                     * @name Base64#decode
                     * @param {string}
                     *            input the base64 encoded string
                     * @returns {string} the decoded string
                     */
                    decode : function(input) {
                        //...
                    }
                };
            }]);
}(angular));

我确定我错过了一些简单的东西......


4156
2018-05-12 20:09


起源

对于有此问题的其他人,请参阅 这里 如何格式化ngdocs - Jamie


答案:


这就是我最终做的事情

(function(angular) {
    'use strict';

    /**
     * @ngdoc overview
     * @name services.base64
     */
    angular.module('services.base64', [])
    .factory(
            'Base64',
            [function() {

                /**
                 * @ngdoc service
                 * @name services.base64.Base64
                 * @description Provides encoding a string into base64, and decode base64 to a string
                 */
                return {
                    /**
                     * @ngdoc method
                     * @name encode
                     * @methodOf services.base64.Base64
                     * @param {string}
                     *            input the string you want to encode as base64
                     * @returns {string} the base64 encoded string
                     */
                    encode : function(input) {
                        //...
                    },

                    /**
                     * @ngdoc method
                     * @name decode
                     * @methodOf services.base64.Base64
                     * @param {string}
                     *            input the base64 encoded string
                     * @returns {string} the decoded string
                     */
                    decode : function(input) {
                        //...
                    }
                };
            }]);
}(angular));

这看起来像我想要的那样......也许有一种不那么冗长的做法呢?


11
2018-05-23 18:49



我离电脑好几天了,但我认为有一个@module指令可以使用。 - hippeelee
添加 @methodOf 为我做了。 - borisdiakur


问题出现了,因为您需要为您的方法提供适当的父级(服务,对象等)。因为您尝试设置父级 services.base64.Base64 在函数返回语句中,它没有正确设置。将注释块移动到某个函数后,就可以将其正确解释为方法父级,然后进行处理。


2
2017-08-25 19:08