javascript - angularjs 错误:[$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"> </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>
当模块由于某些异常而无法加载时会发生此错误,但我不明白为什么它无法加载?谁能启发我。谢谢
解决方案
模块定义中缺少括号以及代码末尾的括号和括号:
(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
();
我为你做了那个小提琴
推荐阅读
- java - 将原始文本添加到 SOAP 标头
- c - 找到时无法返回树节点
- javascript - 如果 setAttribute() 是定义的变量,它不会“记住”函数中分配给它的 ID 的值吗?
- https - 带有letsencrypt的KeystoneJS - 需要证书文件
- netlify - 是否可以在 netlify.toml 文件中设置 access_token ?
- java - 从 Eclipse Oxygen 到 Wildfly 12 的 EAR 部署
- python - 试图理解连接字符串输出的空间复杂度
- rxjs - withLatestFrom 使用两个 Redux 操作
- c - 读取保存文件时,链接类型 1 不支持入站/出站
- python - python套接字,试图在服务器和客户端之间进行登录交互