【问题标题】:AngularJs ngdocs: annotate that a method returns a promiseAngularJs ngdocs:注释一个方法返回一个promise
【发布时间】:2015-08-13 19:03:51
【问题描述】:

我目前正在记录我的第一个真正的 AngularJs 应用程序,因为我正在使用带有 grunt-ngdocs 的 ngdocs 语法

我想知道是否有更好的方法来注释我的服务方法返回一个承诺(所以你知道你应该附加一个 .then() 而不是访问返回对象。

   * @returns {object} returns a promise

服务的完整上下文:

/**
 * @ngdoc service
 * @name appServices.Authentication
 * @requires $http
 * @description
 * Service used to authenticate request to an api. It injects a session parameter into each request if the token parameter is set.
 * (as a request param for a GET and as an extra body param for a POST)
 **/
module.factory('Authentication', ['$http', function ($http) {

    var token;

    /**
     * @ngdoc method
     * @name appServices.Authentication#login
     * @methodOf ng.service
     * @returns {object} returns a promise
     */
    function login(email, password) {
        return $http.post('/auth/login', {email: email, password: password})
            .then(function (response) {

                if (response.data.token) {
                    token = response.data.token;
                }
            });
    }

    function getToken() {
        return token;
    }

    return {
        login: login,
        token: getToken,
    };
}]);

【问题讨论】:

    标签: javascript angularjs grunt-ngdocs


    【解决方案1】:

    你可以简单地写:

    * @returns {Promise} returns a promise
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      • 2014-10-21
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 2018-02-23
      • 2019-09-17
      相关资源
      最近更新 更多