6

I would like to add ngdoc documentation to a function declaration within an angular service. How can I do this for myFunction in the example below?

I reckon I need something like @closure, @functionOf or @functionIn.

Please note that (in contrast to myMethod) myFunction is not a method.

/**
 * @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);
      }
    };
  })
4

3 回答 3

6

您要查找的键名是@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){...}
}
于 2015-10-08T18:05:49.397 回答
0
/**
 * @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
   }

}]);
于 2016-06-16T22:51:08.590 回答
0

我只有 JSDoc 的经验,没有 ngdoc 的经验,但你试过@memberOf而不是@methodOf

链接到 memberOf 的 JSDoc 页面

于 2016-04-08T21:00:16.880 回答