var app = angular.module('part3', []);
app.controller('Part3Controller' ,function ($scope) {
$scope.Message1 = "apek";
$scope.IsLogedIn = false;
$scope.Message = '';
$scope.Submitted = false;
$scope.IsFormValid = false;
$scope.LoginData = {
UserName: '',
Password: ''
};
$scope.$watch('f1.$valid', function (newVal) {
$scope.IsFormValid = newVal;
});
$scope.Login = function() {
$scope.Submitted = true;
if ($scope.IsFormValid) {
alert("eeeeee")
alert("dsds")
serv.GetUser($scope.LoginData).then(function (d) {
alert("dsdsdfsdfs");
if (d.data.UserName != null) {
alert("he;llo1");
$scope.IsLoggedIn = true;
$scope.Message = "Successfully Login" + d.data.FullName;
}
else {
alert("Invalid Credential")
}
})
}
}
})
app.factory('serv', function ($http) {
alert("helloo");
var fac = {};
fac.GetUser = function (d) {
$scope.Submitted = true;
return $http({
url: '/Data/UserLogin',
method: 'POST',
data: JSON.stringify(d),
header: { 'content-type': 'application/json' }
});
};
return fac;
});
我上面的代碼寫入用於登錄功能在我的應用程序,但它不是主叫工廠「SERV」其表示錯誤「angular.min.js:92的ReferenceError:SERV沒有定義」工廠
「angular.min.js:92的ReferenceError:SERV沒有定義」
它仍然不執行「URL:‘/數據/用戶登陸’,」用戶登陸功能DataController類在MVC –
顯示工廠密碼 –
.factory(「login服務」,功能($ HTTP){ 警報( 「helloo」); VAR FAC = {}; fac.GetUser =功能(d,E){ $ scope.Submitted = TRUE; 回報$ HTTP({ 網址:'/ Data/UserLogin', 方法:'POST', data:JSON.stringify(d), header:{'content-typ e':'application/json'} }); alert(4) }; return fac; }); –