我有這個簡單的HTML表單,如下所示,我正在使用Angular js(請參閱控制器 - 表單沒有被提交,並且由於某些原因,我無法讀取值我在網上查和堆棧溢出等問題,但沒有成功的任何指針或指導 - 我失去了什麼在此先感謝:AngularJS表單不會提交
<!doctype html>
<html ng-app="auth">
<head>
<title>Hello AngularJS</title>
</head>
<body>
<form method="post" ng-submit="login()" novalidate ng-controller="Login">
DBID<input type="text" name="dbId" value="23" ng-model="dbId" />
UserName<input type="text" name="username" value="[email protected]" ng-model="username" />
Password<input type="text" name="password" value="test1234" ng-model="password" />
<input type="submit" id="submit" value="login" />
<pre>list={{list}}</pre>
<p>The Token is: {{token}}</p>
</form>
<script src="Scripts/angular.js"></script>
<script src="Scripts/login.js"></script>
</body>
</html>
這裏是我的AngularJS控制器:
?var auth = angular.module('auth', []);
auth.controller('Login', function ($scope, $http)
{
$scope.login = function()
{
if ($scope.dbId)
{
$scope.list.push(this.dbId);
$scope.text = '';
}
};
var Credentials = new Object();
Credentials.DBID = "23";
Credentials.username = "[email protected]";
Credentials.password = "test1234";
$http({
dataType: 'json',
method: 'POST',
url: 'http://localhost:55049/api/Security/Login',
data: Credentials,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic VGVzdEFwcGxpY2F0aW9uVG9rZW46'
}
}).then(function (response)
{
$scope.token = response.data;
});
});
感謝
非常感謝!它正在工作! – CrystalLake62