angularjs error : [$injector:modulerr]



这是使用angularjs模块的login.js,代码视图为index.hbs

(function () {
	'usestrict';
"the initialize angular module"
	angular.module("myAdmin").controller('loginCtrl', function($scope, $http){
		$scope.login = function() {
	$http.post('/admin/',{useremail:$scope.userEmail, userpassword:$scope.userPassword}).
		then(function(response) {
	console.log("posted successfully");
	window.location.href="/admin/home";
	}).catch(function(response) {
	console.error("error in posting");
	})
	}	
	}
)();
<!DOCTYPE html>
<html lang="en" >
<head>
<title>Awi Admin</title>
<meta charset="utf-8">
<meta name="description" content="Aplikasi AWI Realtime Lelang Menggunakan Framework ExpressJS dan Realtime Database Firebase">
<meta name="author" content="Muhammad Abubakar Siddiq - MAS Abbe">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel='stylesheet' href='/stylesheets/login.css'/>
<link rel="stylesheet" type="text/css" href="/stylesheets/font-awesome.min.css">>
</head>
<body ng-app="myAdmin">
<div class="container">
<div class="profile">
<button class="profile__avatar" id="btn_avatar">
<img src="/images/avatar.png" alt="Avatar" />
</button>
<div class="profile__form">
<div class="profile__fields">
<h3 class="text-center">Welcome Admin Lelang</h3>
<form name="login-form" role="form" ng-controller="loginCtrl">
<div class="fields">
<input type="text" class="input" required-pattern=.*S.* id="username" placeholder="Username" ng-model="userEmail"/>
<label class="label" for="fieldUsername">Username</label>
</div>
<div class="fields">
<input type="password" class="input" required-pattern=.*S.* id="password" placeholder="password" ng-model="userPassword"/>
<label class="label" for="fieldPassword">Password</label>
</div>
<div class="alert alert-warning" id="warning">
<em class="fa fa-lg fa-warning">&nbsp;</em>Peringatan, username atau password salah
</div>
<div class="profile__footer">
<center>
<button class="btn" id="btn-submit" ng-click="login()">LOG IN</button>
</center>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
document.getElementById('btn_avatar').addEventListener('click', 
function () {
[].map.call(document.querySelectorAll('.profile'),
function(el) {
el.classList.toggle('profile--open');
});
}
);
</script>
<script type="text/javascript" src = "/javascripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src = "/javascripts/bootstraps/bootstrap.min.js"></script>    
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js"></script> ==> "this is the angular cdn"
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular-resource.min.js"></script>
<script type="text/javascript" src = "/javascripts/login.js"></script> ==> "this is the angular function module init"
</body>
</html>

github 中的问题

当一个模块由于某些异常而无法加载时,就会出现这个错误,但我不明白为什么它不能加载?有人能照亮我吗?谢谢

模块定义处缺少括号,代码末尾缺少括号:

(function () {
'usestrict';
"the initialize angular module"
angular.module("myAdmin", [])// If your defining your module you have to include dependencies, if there is no dependencies array is empty: []
.controller('loginCtrl', function($scope, $http){
$scope.login = function() {
$http.post('/admin/',{useremail:$scope.userEmail, userpassword:$scope.userPassword}).
then(function(response) {
console.log("posted successfully");
window.location.href="/admin/home";
}).catch(function(response) {
console.error("error in posting");
})
}   
}
)
}) // <- theses bracket and parenthesis are missing
();

我为你做了那个小提琴

(function () {
'usestrict';
"the initialize angular module"
angular.module("myAdmin",[]).controller('loginCtrl', function($scope, $http){
$scope.login = function() {
$http.post('/admin/',{useremail:$scope.userEmail, userpassword:$scope.userPassword}).
then(function(response) {
console.log("posted successfully");
window.location.href="/admin/home";
}).catch(function(response) {
console.error("error in posting");
})
}   
}
)
}) // <- theses bracket and parenthesis are missing
();
<!DOCTYPE html>
<html lang="en" >
<head>
<title>Awi Admin</title>
<meta charset="utf-8">
<meta name="description" content="Aplikasi AWI Realtime Lelang Menggunakan Framework ExpressJS dan Realtime Database Firebase">
<meta name="author" content="Muhammad Abubakar Siddiq - MAS Abbe">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel='stylesheet' href='/stylesheets/login.css'/>
<link rel="stylesheet" type="text/css" href="/stylesheets/font-awesome.min.css">>
</head>
<body ng-app="myAdmin">
<div class="container">
<div class="profile">
<button class="profile__avatar" id="btn_avatar">
<img src="/images/avatar.png" alt="Avatar" />
</button>
<div class="profile__form">
<div class="profile__fields">
<h3 class="text-center">Welcome Admin Lelang</h3>
<form name="login-form" role="form" ng-controller="loginCtrl">
<div class="fields">
<input type="text" class="input" required-pattern=.*S.* id="username" placeholder="Username" ng-model="userEmail"/>
<label class="label" for="fieldUsername">Username</label>
</div>
<div class="fields">
<input type="password" class="input" required-pattern=.*S.* id="password" placeholder="password" ng-model="userPassword"/>
<label class="label" for="fieldPassword">Password</label>
</div>
<div class="alert alert-warning" id="warning">
<em class="fa fa-lg fa-warning">&nbsp;</em>Peringatan, username atau password salah
</div>
<div class="profile__footer">
<center>
<button class="btn" id="btn-submit" ng-click="login()">LOG IN</button>
</center>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
document.getElementById('btn_avatar').addEventListener('click', 
function () {
[].map.call(document.querySelectorAll('.profile'),
function(el) {
el.classList.toggle('profile--open');
});
}
);
</script>
<script type="text/javascript" src = "/javascripts/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src = "/javascripts/bootstraps/bootstrap.min.js"></script>    
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular-resource.min.js"></script>
<script type="text/javascript" src = "/javascripts/login.js"></script>
</body>
</html>

最新更新