javascript - AngularJS错误: [$injector:modulerr]

标签 javascript angularjs

这是使用 angularjs 模块的 login.js 和代码 View 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>

issue in 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
    ();

我已经做到了fiddle为你

关于javascript - AngularJS错误: [$injector:modulerr],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51638453/

相关文章:

JavaScript window.open onclick ('url' )

javascript - 使用 JavaScript 将按钮中的字符串添加到 HTML 字段

javascript - 在 yii 中创建跨域通信的 API

javascript - 为什么此应用程序中的绑定(bind)无法更新?

angularjs - Controller 与指令的区别以及何时使用?

javascript - 向弹出窗口添加 24 小时 cookie 使其根本不显示?

javascript - 为什么 Laravel Blade $errors 数组中没有错误会破坏我的 JavaScript

javascript - 单击按钮时在模式内显示 div

javascript - 是否应该在 AngularJS 上设置 angular.module 变量

javascript - Angular 注销不会清除本地存储