Angularjs错误,Module' testApp'不可用

时间:2017-02-23 12:17:25

标签: angularjs angularjs-scope angular-ui-router

<html>
<head>
<script type="text/javascript" src="js/angular/angular.js"></script>
<script type="text/javascript" src="js/angular/angular-route.js"></script>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<title></title>
<meta name="author" content="Stanislau">
<link href="css/style.css" rel="stylesheet">
</head>
<body ng-app="testApp">
    <div ng-controller="testCtrl">
            {{Message}}
    </div>
</body>
</html>

main.js代码

var app = angular.module('testApp', ['ngRoute']);
app.controller('testCtrl', function($scope){
    $scope.Message = '123';
});

错误: angular.js:68未捕获错误:[$ injector:modulerr]由于以下原因导致无法实例化模块testApp: 错误:[$ injector:nomod]模块&#39; testApp&#39;不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。 http://errors.angularjs.org/1.6.1/ $注射器/ NOMOD?P0 = testApp

如果代码:

<html>
<head>
<script type="text/javascript" src="js/angular/angular.js"></script>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<title></title>
<meta name="author" content="Stanislau">
<link href="css/style.css" rel="stylesheet">
</head>
<body ng-app="testApp">
    <div ng-controller="testCtrl">
            {{Message}}
    </div>
</body>
</html>

main.js代码:

var app = angular.module('testApp', []);
app.controller('testCtrl', function($scope){
    $scope.Message = '123';
});

错误是一样的!!

测试版本地址:http://zadanie.salesdep.by/

1 个答案:

答案 0 :(得分:0)

代码工作正常。请检查库引用路径

<div ng-app="testApp" ng-controller="testCtrl">
<div ng-controller="testCtrl">
            {{Message}}
    </div>
</div>

<script>
var app = angular.module('testApp', []);
app.controller('testCtrl', function($scope){
    $scope.Message = '123';
});
</script>