I am trying to create a login page where the log in credential is checked in Backend and returns data... So I am using angular js for front end.
When I make a restful API call, it checks for the login credential but i am not getting the data back from the backend.
Ajax call to my API returns undefined so I am not able to display the response.data
Controller: angular.module('myApp')
.controller('LoginCtrl', function ($scope, $location, LoginService) {
$scope.loginData = {};
$scope.errors = [];
this.msg={};
$scope.login = function () {
if ($scope.loginData != null) {
console.log('Login Controller');
console.log($scope.loginData);
LoginService.Login($scope.loginData).then(function (response) {
console.log('Login Controller2');
$scope.showHide="IsVisible";
$scope.msg=response.data;
$location.path('signIn');
$scope.statuscode = response.status;
console.log(response.status);
console.log(response.headers);
console.log(response.config);
console.log(response.statusText);
console.log(response.xhrStatus);
//console.log(statuscode);
//console.log(msg.message);
console.log(response.data);
var result = response.resource;
// result.$status = response.status;
// console.log(result.$status);
}, function (reason) {
// $scope.errors.push(reason.data.toString());
});
Service: angular.module('myApp') .factory('LoginService', ['$http', function ($http) {
return {
Login: function(loginData){
console.log('Login Service');
console.log(loginData.password);
return $http.get('api/userlogin/checklogin', {params: {username: loginData.username, password:loginData.password}}) .then(testSuccess)
.catch(testError);
function testSuccess(response){
console.log('Login Successful');
console.log(response.data);
return response.data;
//console.log(response.data) this line prints data to console
}
function testError(error){
return error;
}
},
How can I get the data from the server and display the data in html?