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

时间:2016-07-05 04:50:01

标签: javascript angularjs api web

我们无法在角度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); 

     };

};

1 个答案:

答案 0 :(得分:0)

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

$http.post(utils.apiUrl('admin/login', credentials, config).then(function(response) {
    return response;
});