Angularjs 如何使用ngdoc记录角度服务中的函数声明?
我想将ngdoc文档添加到angular服务中的函数声明中。在下面的示例中,如何为myFunction执行此操作 我想我需要像@closure、@functionOf或@functionIn这样的东西Angularjs 如何使用ngdoc记录角度服务中的函数声明?,angularjs,documentation,ngdoc,Angularjs,Documentation,Ngdoc,我想将ngdoc文档添加到angular服务中的函数声明中。在下面的示例中,如何为myFunction执行此操作 我想我需要像@closure、@functionOf或@functionIn这样的东西 请注意(与myMethod相反),myFunction不是一个方法 /** * @ngdoc service * @name myApp.service:myService * @description * My application. */ angular .module('
请注意(与myMethod相反),myFunction不是一个方法
/**
* @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);
}
};
})
您要查找的关键字名是
@methodOf
注释。
当我使用grunt ngdocs为服务编写文档时,结果如下所示:
/**
* @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){...}
}
我只对JSDoc有经验,而不是ngdoc,但您是否尝试过
@memberOf
而不是@methodOf
感谢您写下答案。然而,我的问题是如何记录不是服务方法的函数声明。在我给出的代码示例中,我想找到一种将ngdoc与myFunction一起使用的方法(这不是一种方法)。代码示例还说明了methodOf与myMethod(这是一种方法)一起使用的用法。在您的示例中,doSomething是一种方法,因此使用methodOf是有意义的。到目前为止,我还没有找到一种使用ngdoc的方法来使用
@memberOf
、@member
或@private
,将myFunction
记录为生成myService
的函数的闭包内。JSDoc中有相当一部分功能在ngdoc中似乎不可用。谢谢你的帮助。我在这里找到了ngdocs的文档:这里:myFunction不是一个方法
/**
* @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
}
}]);