angularjs - 在 AngularJS 中使用 ngdocs 和 Controller 属性

标签 angularjs jsdoc jsdoc3 grunt-ngdocs

我刚刚开始在我的 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/

相关文章:

jsdoc - "valid"JSDoc 是否需要星号?

node.js - 创建 NPM 包,如何记录它们?

javascript - JSDoc:返回对象结构

javascript - 为什么 JavaScript 函数文档位于函数之外?

javascript - 将表单传递给 AngularJS 组件进行验证

javascript - AngularJS : difference between views and templateUrl

javascript - 可读的 Angular.js 错误?

javascript - 使用Angularjs定期刷新html表格数据

javascript - jsdoc @link 不起作用

javascript - JSDoc:在另一个@param 中引用方法的@param