A comprehensive guide to understanding controllers: ngdoc documentation

I am new to code documentation and currently attempting to document my Angular application using grunt-ngdocs.

After cloning a functional example from: https://github.com/m7r/grunt-ngdocs-example, I noticed that the provided example did not include documentation for a controller. Thus, I decided to add my own documented controller with the following code:

 /**
  * @ngdoc controller
  * @name rfx.controller:testCtrl
  * @description 
  * Description of controller.
  */
 .controller('testCtrl', function() {
 });

However, when attempting to generate documentation by running grunt from the command line, an error message is displayed:

Warning: Don't know how to format @ngdoc: controller Use --force to continue.

I have consulted this guide but I cannot seem to resolve why I keep encountering errors while trying to document a controller. Any assistance would be greatly appreciated! Thanks!

Answer №1

Below is a guide on how to document a sample controller:

/**
 * @ngdoc function
 * @name appModernizationApp.controller:DetailsCtrl
 * @description
 * # DetailsCtrl
 * Controller of the appModernizationApp
 * This particular controller is in charge of displaying the details of the page.
 * It starts by fetching the JSON data for the different room types from the server upon initialization.
 * Additionally, it also requests the details of a specific room for an existing reservation if there is a reservation id present in the route using <b>HRS.getRegisteredData(reservationId)</b>.
 * @requires $scope
 * @requires $http
 * @requires HRS
 * @requires $location
 * @requires $routeParams
 * @requires breadcrumbs
 * @requires UtilitiesService
 * 
 * @property {object} breadcrumbs:object breadcrumbs Manages the top navigation at the page level.
 * @property {array} reservationDetails:array Contains the reservation details of the current/selected reservation.
 * @property {string} registerationErrorMsg:string Stores error messages related to registration services.
 * @property {string} roomSearchErrorMsg:string Stores error messages related to room search services.
 * @property {array} roomDetails:array Holds the room details object. This object is directly retrieved from the service response and may be manipulated based on the view model.
 * @property {boolean} submitted:boolean Tracks the submission status. Initialized as false and set to true after storing the details.
 * @property {number} reservationId:number Retrieves the reservation id from the route parameters.
 * @property {date} minDate:date Represents the minimum date value filled in.
 * @property {boolean} isRoomDetailsVisible:boolean Manages the visibility of room details through a boolean flag. Initially set to false.
 * @property {array} roomTypes:array Stores the types of rooms obtained from the JSON data.
 * @property {array} expirymonth:array Lists months from January to December
 * @property {array} expiryYear:array Includes years within a specific range
 * @property {array} cardtype:array Specifies the types of cards available
 */

Answer №2

The example repository seems to have an outdated version of grunt-ngdocs listed as a dependency. The latest @ngdoc controller is supported in version 0.2.2, while the repository lists ~0.1.1. Upgrading to the newest version of grunt-ngdocs should resolve this issue.

It's important to note that the recommended tool for generating Angular documentation is dgeni along with dgeni-packages. This combination is used by Angular 1.x for its own documentation generation. Despite its flexibility and extensibility, setting it up may require some time.


Edit: I have forked the grunt-ngdocs-example repository here, updated the grunt-ngdocs version, and included a controller example.

Answer №3

Utilize dgeni to incorporate a custom controller template:

  1. Create a file named controller.template.html within the directory config/template/ngdoc/api. Include the content
    {% extends "api/object.template.html" %}
    (this will inherit from the object template allowing you to write your own custom template)
  2. In the dgeni configuration, expand the idTemplates in the computeIdsProcessor

    config(function (computeIdsProcessor) {
    computeIdsProcessor.idTemplates.find(function (idTempl) {
        return idTempl.idTemplate === "module:${module}.${docType}:${name}";
    }).docTypes.push("controller");})
    
  3. Don't forget to include "controller" in the computePathsProcessor

    .config(function (computePathsProcessor) {
    computePathsProcessor.pathTemplates.push({
        docTypes: ['provider', 'service', 'directive', 'input', 'object', 'function', 'filter', 'type', 'controller'],
        pathTemplate: '${area}/${module}/${docType}/${name}',
        outputPathTemplate: 'partials/${area}/${module}/${docType}/${name}.html'
    });})
    

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to update the value within an object in an array stored in a BehaviorSubject?

My initial data is: const menuItems = [{id: 1, active: false}, {id: 2, active: false}] public menuSubject$ = new BehaviorSubject<MenuItem[]>(menuItems); public menu$ = this.menuSubject$.asObservable(); I am attempting to update the element with ...

Switch out the image source and add attributions until the AJAX call is complete

<div id="fbAdsIconDiv" class="social_icon"> <img src="~/Content/images/fbAdsAddOn_1.png" onclick="toggleImage(this)" id="fbAdsAddOn" data-toggle="tooltip" title="click to enable" class="confirmBox f ...

I've come across some strange JavaScript code while tinkering with an Express/Socket.io application

I am currently working on developing an app similar to SCADA using Brian Ford's amazing https://github.com/btford/angular-socket-io-seed as a starting point. However, I have encountered some JavaScript code that I find quite confusing. I have tried se ...

applying various conditions to JavaScript arrays for filtering

After spending countless hours trying to solve my filtering issue, I'm still struggling. I'm in the middle of creating a react marketplace where users need to be able to apply multiple filters on one page. Here's an example of my product lis ...

How to deactivate a button in AngularJS after it has been clicked

Hey there, I've got a form with various inputs such as email, title, and color... Within this form, I have two buttons: "Save" and "Undo changes". I want these buttons to be disabled by default unless any changes are made. For instance, if I start t ...

Tips for modifying HTML elements and navigating to a different webpage

As I delve into the world of front-end web development, I decided to challenge myself with a little exercise by creating a basic HTML form. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta ...

Having trouble with calling an AngularJS API URL?

app.controller('Ctrl', function ($scope, $http) { $http({method: 'GET', url: "/api/v1/coupons-dunia/coupons-by-website?websiteId=1"}).success(function(data) { $scope.onlinedata = data.coupons; $scope.websi ...

Remove each notification automatically in JavaScript after a specified period of time

I'm currently developing a basic notification system. Check out the jsfiddle I created here: https://jsfiddle.net/t9pvmzhh/3/ For some reason, jsfiddle is not showing all 4 notifications even though they display correctly on my end. I suspect there ...

Can express middleware be tailored for each individual handler within the same route path?

I am seeking to create distinct routes under an /api path with varying middleware handlers, each allowing for different authentication methods. My initial approach was to nest these API routes under separate instances of the Router object using Express: c ...

What about creating a PHP-MySQL voting platform?

I have implemented a PHP-MySQL voting system on my website, similar to YouTube's. I am using AJAX to execute the PHP in newtest.php. The PHP script works fine when tested individually, but when trying to implement the voting functionality through AJAX ...

Guide on showcasing an array in a table using DataTables in a single column

I find myself in a difficult situation because I am using DataTables for pagination and searching in an unconventional way. I have a table where I display vendor details such as names, emails, addresses, countries, and the materials they deal with. To fetc ...

Is there a way to retrieve JSON data using Vue and Axios?

I'm facing an issue trying to retrieve product data from a JSON file. Despite attempting different methods and searching for solutions online, I have not been able to find one that fits my specific scenario. As I am new to both Vue and axios, I apprec ...

Is there a way to add a sub-heading into the side menu?

We are currently developing an application that utilizes ngCordova and we want to implement a side menu feature. The side menu has already been set up and you can see it below. https://i.stack.imgur.com/fiv39.png After adding the subheader, this is how t ...

React - A guide on accessing the scroll position of a div using JavaScript

Within my side navigation bar, there is a title and other information. The title is fixed in place (sticky) and the sidebar has a height of 100vh. I am looking to add a box-shadow effect to the title div (sticky-title) only when the user scrolls down past ...

Is there a way to get a Chrome extension to run automatically in the background?

I am looking to develop a custom chrome extension with a countdown timer functionality that automatically runs in the background. However, I am facing an issue where my background.js file is unable to access the popup.html file. How can I execute scripts i ...

Creating a custom HTML5 pattern for formatting Pakistani phone numbers

For my HTML5 pattern for Pakistan Phone Number Format, I have the following criteria: 03xx-xxxxxxx My current regex code is as follows: /03[0-9]{2}-[0-9]{7}/ Now, I want to ensure that the next 7 digits after the hyphen meet the following conditions: ...

Transform an image into Base64 format by effortlessly dragging and dropping

I am looking to add a specific feature to my website that can be implemented solely on the client side using JavaScript or any JavaScript library. The requirement is to allow users to drag and drop an image from their local machine directly into the brows ...

"Bower fetches and installs specific versions of packages from the repository

I'm currently using npm 3.3.6 and bower 1.6.8 on Windows 10. Whenever I attempt to install a package like jquery or framework7, it ends up downloading and installing an archived version of the package. Here's an example: > bower install jquer ...

Utilizing jQuery and JSON to showcase the contents of an array

My goal is to display all the items in an array by utilizing JSON and jQuery from the Song of Ice and Fire API. Currently, I am only able to display one item from each of the arrays. If you want to view the codepen, click here: https://codepen.io/frederic ...

Running on Node.js, the Promise is activated, yet there remains an issue with the function

I've encountered a strange issue that I can't seem to diagnose. It's showing a TypeError: My code is returning 'function is undefined', which causes the API call to fail. But oddly enough, when I check the logs and breakpoints, it ...