Angular 1.4.8错误:[$ injector:modulerr]

时间:2015-12-03 06:34:27

标签: javascript html angularjs

我无法找到/查明错误的根本原因。 在我的javascript文件中,我一直在angular这个词下面变成绿色波浪形。我不明白为什么。 (我使用Visual Studio代码)

HTML

<html ng-app="myapp">
        <head>
            <title>Hello</title>

            <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
                    <script type="text/javascript" src="C:\Users\john\Desktop\test.js"/>

        </head>
        <body >
            <div>
                <label>Name:</label>
                <input type="text" ng-model="yourName" placeholder="Enter name here">

                <h1> Hello, {{yourName}}</h1>

                <div ng-controller="HelloController">
                    <h2>Say hello to {{helloTo.title}} </h2>
                    </div>


         </body>
    </html>

Javascript

(function(){
var app = angular.module('myapp', ['ngRoute']);

app.controller("HelloController", function($scope){
    $scope.helloto={};
    $scope.helloto.title="AngularJS";

});

})();

ERROR

 Uncaught Error: [$injector:modulerr]  http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=myapp&p1=Error%3A%20%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.8%2F%24injector%2Fnomod%3Fp0%3Dmyapp%0A%20%20%20%20at%20Error%20(native)%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A6%3A416%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A24%3A186%0A%20%20%20%20at%20b%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A23%3A251)%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A23%3A494%0A%20%20%20%20at%20https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A38%3A117%0A%20%20%20%20at%20n%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A7%3A333)%0A%20%20%20%20at%20g%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A37%3A488)%0A%20%20%20%20at%20eb%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A41%3A249)%0A%20%20%20%20at%20c%20(https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.8%2Fangular.min.js%3A19%3A463

3 个答案:

答案 0 :(得分:4)

您缺少ng-route的javascript文件。

https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.2/angular-route.min.js

这是它的cdn。加载它,它应该工作。

答案 1 :(得分:1)

您必须参考ng-route

的脚本
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-route.js">

答案 2 :(得分:1)

好像你没有添加ng-route.js文件,因为你需要angular.module('myapp', ['ngRoute']);

尝试在js文件中的angular.js之后立即添加此html

https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-route.js

并检查C:\Users\john\Desktop\test.js是否正确加载