I am creating a anjular js app where i have created a login page and i m authenticating it using web api. This is the controller which is returning json and it is running properly.
[Route("api/Customer/{id}/{pass}")]
public IEnumerable GetCustomer(string id, string pass)
{
var list = repository.Get(id, pass);
if (list != null)
{
return list;
}
else
{
return null;
}
}
this is the controller accessing the api in angular app (demoApi.js)
(function () {
'use strict';
var DemoApi = function ($http) {
var loginCheck = function (username, password) {
return $http.get("http://localhost:8115/api/Customer/" +username+"/"+password)
.then(function (response) {
return response.data;
});
};
return {
loginCheck: loginCheck
}
};
var app = angular.module("angularApp");
app.factory("DemoApi", DemoApi);
}());
this is the login controller(loginController.js)
(function () {
var app = angular.module("angularApp");
var loginController = function ($scope, $http, bankApi, $location) {
var userDetails = {
username: $scope.uName,
password: $scope.uPassword
};
$scope.login = function () {
DemoApi.loginCheck(userDetails.username, userDetails.password)
.then(onLogin, onError);
};
var onError = function (reason) {
$scope.error = "Could not fetch the data.";
};
var onLogin = function (data) {
$scope.details = data;
$location.path("/info");
};
}
app.controller('loginController', loginController);
}());
this is the index page where i have all the scripts linked
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="angularApp">
<head>
<title>Ebank</title>
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-route.js"></script>
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script src="lib/app.js"></script>
<script src="lib/bankApi.js"></script>
<script src="lib/loginController.js"></script>
<script src="lib/infoController.js"></script>
</head>
<body style="background-color:#333">
<div ng-view></div>
</body>
</html>
Provide me with a solution, why i m not able to call api from demoApi.js I'm getting the response if i call this api directly from the html page but not getting response from demoApi.js