所以我收到以下错误和提示:
Failed to instantiate module stable due to:
Error: [$injector:nomod] http://errors.angularjs.org/1.4.9/$injector/nomod?p0=stable
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js:6:416
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js:24:186
at b (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js:23:252)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js:23:495
at https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js:38:153
at n (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js:7:355)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js:38:1)
at db (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js:41:272)
at c (https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js:19:463
Module 'stable' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
所以我试图弄清楚为什么注册不起作用,但到目前为止我没有运气。
我的.js中有这个
/*global angular*/
var stable = angular.module('stable',[]);
stable.controller('mainController', function($scope) {
$scope.master = {};
$scope.login = function() {
var loginAttempt = {
"_userName": $scope.userName;
"_password": $scope.userPassword;
};
console.log(loginAttempt);
};
$scope.create_account = function(user) {};
});
并在我的顶级html标记中包含“ng-app =”stable“”属性。我错过了什么?
HTML代码:
<!DOCTYPE html>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript"src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-route.js"></script>
<html lang="en" >
<br xmlns="http://www.w3.org/1999/html">
<head>
<title>User Login</title>
<style>
body {
background: rgb(210, 77, 87) !important;
}
</style>
</head>
<body ng-app="stable" ng-controller="mainController">
<i><span style="color:#FFFFFF; font-family:Segoe UI Black,serif; font-size:50px; margin-left: 1%; margin-top:1%;">STABLE</span></i>
<!-- onclick="location.href = 'http://localhost:63342/AngularJS/AccountPage.html'" removed from Create Account-->
<button type="button" ng-click="create_user(user)" class="btn btn-primary btn-lg" name="create_user_button" style="float:right; margin-right:2.5%; margin-top:1%;">Create Account</button><br>
<div style="text-align: center;">
<br><br><br><br>
<b><span style="color:#FFFFFF; font-size: 32px;">Hello! Please Sign In.</span></b><br><br>
<input style="font-size:28px;" ng-model="userName" type="text" name="username" id="id_username" placeholder="Username" size="32" maxlength="16" /><br><br>
<input style="font-size:28px;" ng-model="userPassword" type="password" name="password" id="id_password" placeholder="Password" size="32" maxlength="16"/><br>
<a href="http://localhost:63342/AngularJS/PasswordPage.html" style="color:#FFFFFF; font-size: 16px;">Forgot Password?</a>
<br><br>
<!-- onclick="location.href = 'http://localhost:63342/AngularJS/MainPage.html'" removed from button -->
<button type="submit" ng-click="login()" class="btn btn-primary big-btn btn-lg" name="login_button" >Login</button>
</div>
</body>
</html>
答案 0 :(得分:0)
您需要确保您的html中包含模块“stable”的javascript文件包含在脚本标记中。您还需要确保加载angularjs的脚本标记位于此其他javascript文件脚本标记之前。
<script type="text/javascript" src="path/to/angularjs"></script>
...
<script type="text/javascript" src="path/to/js/file"></script>
希望这会有所帮助。发布与此相关的html代码也很有用。如果这不是一个修复。