I'm trying to pull a user's first name after logging in, I'm having problem retrieving the object containing the name.
my service.js:
(function () {
'use strict';
angular
.module('agent')
.factory('viewAgent', viewAgent);
viewAgent.$inject = ['$http', '$log'];
function viewAgent($http, $log) {
var param = {
api_id: '1',
api_key: 'KEY',
api_secret: 'SECRET',
user_email: 'test-email',
user_password: 'test'
};
return {
view: function () {
return $http({
url: 'api/agent/loginViaEmail',
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
$log.log(str);
return str.join('&');
},
data: param
});
}
};
}
})();
the controller.js:
(function () {
'use strict';
angular
.module('agent')
.controller('AgentController', AgentController);
AgentController.$inject = ['viewAgent', '$state', '$log'];
function AgentController(viewAgent, $state, $log) {
var vm = this;
vm.agents = [];
viewAgent.view()
.then(function success(res) {
$log.log(res.data);
vm.agents = res.data.basicInfoAgent;
return res.data;
},
function error(error) {
$log.log(error);
});
}
})();
login controller:
function loginClick() {
viewAgent.view();
}
and my html:
<div ng-controller="AgentController">
<md-button ng-click="vm.loginClick()" ng-disabled="login.$invalid">Login</md-button>
<div>{{vm.agents}}</div>
</div>
I'm getting a 400: Bad Request error that says, "There are missing parameter field".I'm not sure what to fix. I've tried retrieving the data on Postman and I was able to get back the whole user's object.