AngularJS出错-无法实例化模块
Error with AngularJS - failed to instantiate module
我正在为.net book浏览angular,并使用一个带有两个控制器的应用程序的基本示例。然而,我现在收到了这个错误,我不明白为什么它无法实例化模块:
中第4138行第9列出现未处理的异常http://localhost:53990/Scripts/angular.js
0x800a139e - JavaScript runtime error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:nomod] Module 'myApp' 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.
这是我的代码
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="myApp">
<head>
<meta charset="utf-8" />
<title>AngularJS with .NET</title>
<script src="Scripts/angular.js"></script>
</head>
<body>
<h1>Game setup</h1>
<div ng-controller="ExampleController1">
<h2>Player 1</h2>
<label>Name:</label>
<input type="text" placeholder="Please enter player 1 name" ng-model="name" ng-focus="onNameFocused()" />
<h3 ng-show="name">Player 1 name is {{name}}</h3>
<h3 ng-show="previousName">Previous Player 1 name was {{previousName}}</h3>
</div>
<div ng-controller="ExampleController2">
<h2>Player 2</h2>
<label>Name:</label>
<input type="text" placeholder="Please enter player 2 name" ng-model="name" ng-focus="onNameFocused()" />
<h3 ng-show="name">Player 2 name is {{name}}</h3>
<h3 ng-show="previousName">Previous Player 2 name was {{previousName}}</h3>
</div>
<script>
(function () {
"use strict"
var myAppModule = angular.module('myApp', []);
//myAppModule.filter('customname', function () {
// return function (name) {
// name = name || '';
// var customName = "";
// for (var i = 0; i < name.length; i++) {
// if (name.charAt(i) == "e") {
// customName += "3";
// }
// else if (name.charAt(i) == "o") {
// customName += "0"
// }
// else {
// customName += name.charAt(i);
// }
// }
// return customName;
// }
//})
myAppModule.controller('ExampleController1', ['$scope', function
($scope) { // Explicit dependency injection
$scope.name = "Alex Pop";
$scope.previousName = "";
$scope.onNameFocused = function () {
$scope.previousName = $scope.name;
};
}]);
myAppModule.controller('ExampleController2', ['$scope', function ($scope) {
$scope.name = "Alex Pop";
$scope.previousName = "";
$scope.onNameFocused = function () {
$scope.previousName = $scope.name;
};
}]);
console.log(myAppModule.name);
});
</script>
</body>
</html>
有人看到它怎么了吗?
您将整个Angular Script封装在IIFE中,但从未调用函数来加载脚本。
(function () {
...
});
您要么应该打开该函数,要么调用该函数,如下所示:
(function () {
...
}());
相关文章:
- Angular重命名模块后未能实例化模块
- AngularJS出错-无法实例化模块
- 未捕获错误:由于,[$injector:moduler]未能实例化模块polmgr
- 角度错误: [$injector:模块rr] 由于以下原因无法实例化模块角度图表: 错误: [$injector:nom
- 由于以下原因,无法实例化模块 myApp:错误:[$injector:nomod] http://errors.angu
- 未捕获的错误: [$injector:modulerr] 无法实例化模块 toastr
- 无法实例化模块 ng材料
- 无法使用 JSPM 实例化模块 kendo.directives
- 使用 ui-view 导致无法实例化模块 ui.router
- 未捕获的错误: [$injector:modulerr] 由于以下原因,无法实例化模块 myApp: 错误: [$inj
- “由于”在角度和平均堆栈中“无法实例化模块'app'”
- 未捕获错误: [$injector:模块rr] 由于以下原因无法实例化模块启动器:错误: [$injector:模块rr
- Angular:[$injector:modulerr]未能实例化模块
- 未捕获错误:[$injector:moduler]由于以下原因无法实例化模块scheduleApp
- 未能实例化模块[$injector:unp]未知提供程序:$routeProvider
- $state.go无法实例化模块
- Angular--实例化模块失败
- AngularJS:未捕获错误:$injector:modulerr未能实例化模块
- 实例化模块失败错误:[$injector:unpr]
- 未捕获错误:[$injector:modulerr]实例化模块失败,原因是: