首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用ngdoc来记录angular服务中的函数声明?

如何使用ngdoc来记录angular服务中的函数声明?
EN

Stack Overflow用户
提问于 2015-10-08 19:59:55
回答 3查看 4.8K关注 0票数 6

我想将ngdoc文档添加到angular服务中的函数声明中。在下面的示例中,我如何对myFunction执行此操作?

我认为我需要像@closure、@functionOf或@functionIn这样的东西。

请注意(与myMethod相比) myFunction不是一种方法。

代码语言:javascript
复制
/**
 * @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);
      }
    };
  })
EN

回答 3

Stack Overflow用户

发布于 2015-10-09 02:05:49

您要查找的键名是@methodOf注释。当我使用grunt-ngdocs为服务编写文档时,它最终看起来如下所示:

代码语言:javascript
复制
/**
  * @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){...}
}
票数 6
EN

Stack Overflow用户

发布于 2016-04-09 05:00:17

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

Link to JSDoc page for memberOf

票数 0
EN

Stack Overflow用户

发布于 2016-06-17 06:51:09

代码语言:javascript
复制
/**
 * @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
   }

}]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33015175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档