简体   繁体   English

如何使用JSDoc注释AngularJS组件

[英]How to comment AngularJS component with JSDoc

What tag should we use to document an Angular JS component with JSDoc? 我们应该使用什么标签来用JSDoc记录Angular JS组件? I was thinking of using @module, am I right? 我当时在考虑使用@module,对吗?

For example : 例如 :

/**
* @module helloWorld
*
* @description AngularJS component to display a message with a name.
*
*/
angular.component('helloWorld', {
  bindings: {
    name: '@'
  },
  controller : function helloWorldCtrl () {
    this.logName = logName;

    /**
     * @function logName
     *
     * @param {string} msg - message to display with the name.
     *
     * @memberof helloWorld
     *
     * @description Log in the console the message with the name.
     *
     */
    function logName(msg) {
      console.log(msg + this.name);
    }
  },
  template : '<div><span ng-click="$ctrl.logName('Hi ')">{{$ctrl.name}}!</span></div>'
});

I would have the same question for directive, service and controller. 对于指令,服务和控制器,我会有同样的问题。 Besides is my way of using @memberof right? 另外我使用@memberof的方式对吗?

Although JSDoc does have @module , it's a "visibility" specification and I don't think it is what you're looking for. 尽管JSDoc确实具有@module ,但这是一个“可见性”规范,我认为这不是您要寻找的。

The @module tag marks the current file as being its own module. @module标记将当前文件标记为它自己的模块。 All symbols in the file are assumed to be members of the module unless documented otherwise. 除非另有说明,否则假定文件中的所有符号都是模块的成员。

Which might be true, but also might not be. 这可能是正确的,但也可能不是。

The key thing you need to remember is that these annotations should act as a breadcrumb trail so that inherited behavior can be linked to in the documentation and also so that the compiler has as much information about the code as possible. 您需要记住的关键是,这些批注应充当痕迹,以便可以在文档中链接继承的行为,还可以使编译器获得有关代码的尽可能多的信息。

So, when looking for how to document this I'd look up the parts in the Angular externs and @return / @type / @param to match; 因此,当寻找如何记录这一点时,我会在Angular externs@return / @type / @param @type匹配的部分;

@return {angular.Component} Component definition object.

Hope that helps! 希望有帮助!

First define your separate topic in your documentation to listing all modules. 首先,在文档中定义单独的主题以列出所有模块。 For this create some empty file with next annotation: 为此,创建一些带有下一个注释的空文件:

/**
 * @namespace solution_name
 */ 

For module can be used this annotation to have each module defined in its seprarate html page 对于模块,可以使用此注释在其单独的html页面中定义每个模块

/**
 * @class solution_name.MyModule
 * @memberOf solution_name 
 */

Service annotation to be added as part of myModule page documentation 服务注释将作为myModule页面文档的一部分添加

/**
 * @function myService
 * @memberOf solution_name.MyModule
 * @description This is an my service.
 */

Controller can be decorated like this to be listing also inside your module documentation page as separate unit 控制器可以这样装饰,也可以在模块文档页面中单独列出

/**
 * @class solution_name.MyModule.MyController
 */

To create tree structure to combine controllers, services based on businees needs you can also add namespace attribute per your class/function definition 要创建树形结构以合并控制器,基于业务的服务需要,您还可以根据类/函数定义添加namespace属性

/**
 * @namespace MyApp.Controllers
 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM