我刚刚开始在我的 Angular 应用程序中使用 grunt-ngdocs,到目前为止一切顺利。
但我现在想在我的一个 Controller 中记录另一个已记录属性的一些属性。
考虑以下代码:
(function() {
'use strict';
/**
* @ngdoc controller
* @name app.mymodule.controller:MyController
* @description
* A Controller
*/
angular
.module('app.mymodule')
.controller('MyController', Controller);
Controller.$inject = ['someService', 'otherService', '$state'];
function Controller(someService, otherService, $state) {
/**
* @ngdoc property
* @name vm
* @propertyOf app.mymodule.controller:MyController
* @description
* A named variable for the `this` keyword representing the ViewModel
*/
var vm = this,
searchText;
vm.customerService = customerService;
vm.fetchCollection = fetchCollection;
vm.deleteCustomer = deleteCustomer;
initialise();
function initialise() {
//logic
}
/**
* @ngdoc
* @name fetchCollection
* @methodOf app.mymodule.controller:MyController
*
* @description
* Function to retrieve records from the backend service
* @example
* vm.fetchCollection(page, perPage);
* @param {int} page The number of the page of data to be retrieved
* @param {int} perPage The number of items per page to be retrieved
* @returns {object} The response object returned from a httpPromise
*/
function fetchCollection(page, perPage){
//logic
}
function deleteCustomer(model) {
//logic
}
})();
如您所见,我有一些属性卡在 vm 变量上,这些属性通常是对 Controller 中定义的函数的引用。
使用上面的 ngdocs\jsdocs 文档语法,我可以将 vm 属性输出到我的文档文件夹中,但我不确定如何记录 vm 对象本身的属性。
是否有合理或推荐的方法来做到这一点?我确实想知道是否不完全记录 vm 而只是单独记录每个 vm.xxx,但我对此不太确定!
谢谢
最佳答案
documentation中说的不是很清楚,但您必须在名称中使用哈希。
试试这个。
/**
* @ngdoc property
* @name app.mymodule.controller:MyController#vm
* @propertyOf app.mymodule.controller:MyController
* @description
* A named variable for the `this` keyword representing the ViewModel
*/
关于angularjs - 在 AngularJS 中使用 ngdocs 和 Controller 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34531647/