Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can ngdoc be used to document a function declaration in an angular service?

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);
      }
    };
  })
like image 720
paulhhowells Avatar asked Oct 08 '15 11:10

paulhhowells


People also ask

Can typedoc be used to document angular apps?

TypeDoc contains two themes out of the box. The default one and 'minimal'. To specify a theme use* --theme* option followed by the name of the predefined theme or a path to a custom one. While you can use TypeDoc to document Angular apps, it will treat your code as any other plain TypeScript app. That means no Angular specific documentation.

Why use compodoc for angular documentation?

That means no Angular specific documentation. But there is a whole lot to be documented. Compodoc solves this, it is focused on Angular apps specifically giving you a much more tailored solution. Once you run the compodoc command it will automatically generate your documentation from your project in form of HTML.

How do I create a data service in angular?

To create a service in Angular, you need to run the generate service command: Two new files will be created. Navigate to the data service.ts file, and make sure the content is the same as this: This data service has now been created and hard-coded data stored in the getList function.

What is the best tool to write documentation for AngularJS?

One of the common ones is, for example, JSDoc. It is similar to JavaDoc tool used with Java, which can generate automatically documentation based on special comments, which are present directly in the code. However, when working with a framework such as AngularJS (that is -- Angular 1.x), it is handy to have something more powerful.


1 Answers

The keyname you are looking for is the @methodOf annotation. When i'm writing documentation using grunt-ngdocs for a service it ends up looking like the following:

/**
  * @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){...}
}
like image 134
Makarray Avatar answered Nov 15 '22 11:11

Makarray