如何在 Angular js 中使用 Web API 2 ($http post) 方法

问题描述 投票:0回答:1

我们无法在 Angular js 中使用 Web api2 方法

module.exports = function ($http, utils) {
    var self = this;
    self.login = function (credentials) {
        var config = {
            headers: {
                //'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
                'Content-Type': 'application/json'
            }
        };

        return $http.post(utils.apiUrl('admin/login'), credentials, config); 

         };

};
javascript angularjs webapi
1个回答
0
投票

您实际上正在接触服务器,但没有读取响应。由于 $http 返回一个承诺,正确的方法是:

$http.post(utils.apiUrl('admin/login', credentials, config).then(function(response) {
    return response;
});
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.