我正在尝试使用AngularJS
设置一个非常基本的登录功能
这就是我所拥有的:
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home Page - My ASP.NET Application</title>
<link href="/Content/site.css" rel="stylesheet"/>
<script src="/Scripts/angular.js"></script>
</head>
<body ng-app ="MyApp">
<script src="/Scripts/ng/ngLogin.js"></script>
<div id="loginBox" ng-controller="loginCtrl">
<form action="/" id="userLogin">
<label>User id</label>
<input type="text" ng-model="userId" />
<label>Password</label>
<input type="text" ng-model="password" />
<input type="button" name="loginSubmit" ng-click="submit()" value="Login" />
</form>
</div>
</body>
</html>
ngLogin.js
angular.module("MyApp").controller('loginCtrl', ['$scope', '$log', function($scope, $log) {
alert($scope.userId);
$scope.submit = function () {
var usrName = $scope.userId;
var password = $scope.password;
alert(usrName);
$log.log(usrName);
}
}]);
但是当我点击登录按钮时,警报和控制台日志中的任何内容都没有发生,我做错了什么?
答案 0 :(得分:1)
注册模块时传递依赖项数组:
angular.module("MyApp", [])
错误:[$ injector:nomod]模块'MyApp'不可用!你要么 拼写错误的模块名称或忘记加载它。 如果注册了 模块确保您将依赖项指定为第二个 参数强>
答案 1 :(得分:1)
缺少 - []
angular.module("MyApp",[])