Как можно использовать ngdoc для документирования объявления функции в угловом сервисе?

Я хотел бы добавить документацию ngdoc к объявлению функции в угловом сервисе. Как я могу сделать это для myFunction в примере ниже?

Я считаю, что мне нужно что-то вроде @closure, @functionOf или @functionIn.

Обратите внимание, что (в отличие от myMethod) myFunction не является методом.

/**
 * @ngdoc service
 * @name myApp.service:myService
 * @description
 *   My application.
 */
angular
  .module('myApp')
  .factory('myService', function() {
    'use strict';

    var x = 0;

    /**
     * @ngdoc function
     * @name ?
     * @description
     *   How can this be identified as being within the closure of 
     *   myService, and not be described as a constructor?
     */
    function myFunction (z) {
      x++;
      x += z;
    }

    return {
      /**
       * @ngdoc method
       * @name myMethod
       * @methodOf myApp.service:myService
       * @description
       *   A method of myService.
       */
      myMethod : function (x) {
        myFunction(x);
      }
    };
  })

3 ответа

Ключевое имя, которое вы ищете, является @methodOf аннотаций. Когда я пишу документацию, используя grunt-ngdocs для службы, она выглядит примерно так:

/**
  * @ngdoc overview
  * @name module
  * @description A small module containing stuff
  */
angular
  .module(module, [])
  .factory('name', factory);

/**
  * @ngdoc object
  * @name module.name
  * @description Its a pretty bad factory
  */
function factory() {
  return {
    doSomething: doSomething
  };

  /**
    * @ngdoc function
    * @name module.name#doSomething
    * @methodOf module.name
    * @description Does the thing
    * @param {string=} [foo='bar'] This is a parameter that does nothing, it is
                                   optional and defaults to 'bar'
    * @returns {undefined} It doesn't return
    */
  function doSomething(foo){...}
}
/**
 * @ngdoc controller
 * @name MyApp.myController:myController
 * @description
 * This is myController controller.
 **/          
angular.module('MyApp').controller('myController', ['$scope', function($scope) {       

  /**
   * @ngdoc function
   * @name myFunction
   * @methodOf MyApp.controller:myController
   * @description
   * This function does something
   */
   function myFunction(){
    // do something
   }

}]);

У меня есть только опыт работы с JSDoc, но не с ngdoc, но вы пробовали @memberOf скорее, чем @methodOf?

Ссылка на страницу JSDoc для memberOf

Другие вопросы по тегам