我正在使用Wcf服務到Angular JS應用程序。我正在通過提供用戶名和密碼來創建用戶登錄系統。但是,我在輸入中輸入的任何用戶名或密碼都會提示其始終顯示消息用戶名和密碼是否正確。我想如果用戶名和密碼是正確的,那麼我想在角度js應用程序中顯示消息,否則用戶名和密碼是不正確的,但我不知道爲什麼它總是擊中if語句,並沒有關係,如果我輸入錯誤的用戶名或密碼。角JS應用程序始終打如果語句從不去其他語句
這是我的腳本代碼。
///// <reference path="../angular.min.js" />
var app = angular.module("WebClientModule", [])
.controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {
$scope.OperType = 1;
//1 Mean New Entry
//To Clear all input controls.
function ClearModels() {
$scope.OperType = 1;
$scope.Username = "";
$scope.Password = "";
}
$scope.login = function() {
var User = {
Username: $scope.Username,
Password: $scope.Password,
};
myService.AuthenticateUser(User).then(function (pl) {
if (pl.data) {
$scope.msg = "Password or username is correct !";//Always hit on this line
}
else {
$scope.msg = "Password Incorrect !";
console.log("Some error Occured" + err);
}
}, function (err) {
$scope.msg = "Password or username is Incorrect !";
console.log("Some error Occured" + err);
});
};
}]);
app.service("myService", function ($http) {
this.AuthenticateUser = function (User) {
return $http.post("http://localhost:52098/HalifaxIISService.svc/AuthenticateUser", JSON.stringify(User));
}
})
這是我的HTML代碼..
@{
Layout = null;
}
<!DOCTYPE html>
<html ng-app="WebClientModule">
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/RegistrationScript/LoginScript.js"></script>
</head>
<body>
<table id="tblContainer" data-ng-controller="Web_Client_Controller">
<tr>
<td></td>
</tr>
<tr>
<td>
<div style="color: red;">{{msg}}</div>
<table style="border: solid 4px Red; padding: 2px;">
<tr>
<td></td>
<td>
<span>Username</span>
</td>
<td>
<input type="text" id="username" data-ng-model="Username" required="" />
</td>
</tr>
<tr>
<td></td>
<td>
<span>Password</span>
</td>
<td>
<input type="password" id="password" required data-ng-model="Password" require="" />
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>
<input type="button" id="Login" value="Login" data-ng-click="login()" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<script src="~/RegistrationScript/LoginScript.js"></script>
這裏是放出來..
如果嘗試(pl.data = 「」!) –
對不起仍創下if語句 – Mohammad
空輸入fileld其命中else語句 - – Mohammad