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

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

I believe that I need something like @closure, @functionOf or @functionIn.

Note that (unlike 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); } }; }) 
+5
source share
3 answers

The key name you are looking for is the @methodOf annotation. When I write documentation using grunt-ngdocs for a service, it looks like this:

 /** * @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
source

I only have experience with JSDoc, not ngdoc, but have you tried @memberOf , not @methodOf ?

Link to JSDoc page for memberOf

0
source
 /** * @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
source

Source: https://habr.com/ru/post/1233238/


All Articles