如何在文档中描述角度控制器方法?

时间:2015-07-18 07:54:01

标签: angularjs documentation documentation-generation jsdoc ngdoc

我无法描述控制器方法。我怎么能这样做?

/**
* @ngdoc controller
* @name works.controller:worksCtrl
* @requires $http
* @requires $element
* @function
*
* @description
* Description for works controller. All methods will be writen later
*/
var worksCtrl = function ($http, $element) {

    var ctrl = this;

    //how it do there? this not work
    /** 
        * @name initializeGrid
        * @function
        * @description
        * Description for initializeGrid
    */
    ctrl.initializeGrid = function (a) {
       //...
    }

    ctrl.getTemplate = function (workIndex) {
      //...

    }
    //...
};

我正在使用ngdoc来生成自动生成文档。但我无法理解我做错了什么。

2 个答案:

答案 0 :(得分:3)

我从来没有使用过ngdoc,但是想看看角度代码本身,看起来你需要在内部函数的文档中添加@ngdoc method标记。例如,在$ locationProvider里面:

  /**
   * @ngdoc method
   * @name $locationProvider#hashPrefix
   * @description
   * @param {string=} prefix Prefix for hash part (containing path and search)
   * @returns {*} current value if used as getter or itself (chaining) if used as setter
   */
  this.hashPrefix = function(prefix) {
    if (isDefined(prefix)) {
      hashPrefix = prefix;
      return this;
    } else {
      return hashPrefix;
    }
  };

我希望它有所帮助。

答案 1 :(得分:3)

/**
* @ngdoc function
* @name initializeGrid
* @methodOf works.controller:worksCtrl
* @description This method initialize auto grid system for works
* @private
*/

ctrl.initializeGrid = function () {
     ...
}

这就是我所需要的。)