Angularjs-未捕获错误angular.js:78

Angularjs-未捕获错误angular.js:78,angularjs,angular-routing,Angularjs,Angular Routing,我对Angular很陌生,现在正在玩ngRoute。出于某种原因,即使我正在加载angular-route.js模块,我还是会不断地列出错误。我认为路径也可能存在一些问题,但我找不到解决方案。代码粘贴在下面。重要的文件是student.js和student.html。angular.html和testCtrl.js是我构建的简单计算器的文件,单击student.html中的链接时应该加载这些文件 student.js student.html 谢谢你的帮助 您将创建两次模块: student.j

我对Angular很陌生,现在正在玩ngRoute。出于某种原因,即使我正在加载angular-route.js模块,我还是会不断地列出错误。我认为路径也可能存在一些问题,但我找不到解决方案。代码粘贴在下面。重要的文件是student.js和student.html。angular.html和testCtrl.js是我构建的简单计算器的文件,单击student.html中的链接时应该加载这些文件

student.js

student.html


谢谢你的帮助

您将创建两次模块:

student.js

angular.module('testing', ['ngRoute'])  
angular.module('testing', ['ui.bootstrap'])
testCtrl.js

angular.module('testing', ['ngRoute'])  
angular.module('testing', ['ui.bootstrap'])
其中第二个覆盖第一个。要解决此问题,请在
student.js
中声明模块的所有依赖项:

angular.module('testing', ['ngRoute', 'ui.bootstrap'])
然后,要在稍后的
testCtrl.js
中访问该模块,请在不使用第二个参数的情况下调用它:

angular.module('testing')
.controller("TestCtrl", function($scope){
...
更新

另外,Angular是为单页应用程序设计的,因此您的模板应该只是一部分,而不是一个完整的HTML文档,因为
Angular.HTML
在您的代码示例中

因此,您的所有脚本都应该加载到
students.html
,并且您应该删除包装要在
ng视图中显示的内容的所有其他内容

student.html

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-route.js"></script>
    <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script>
    <script src = "student.js" type="text/javascript"></script>
    <script src = "testCtrl.js" type="text/javascript"></script>
    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
    <link href = "angular.css" rel = "stylesheet">
</head>
<body ng-app = "testing">
    <a href = "#/angular">Angular Calculator</a>
    <div ng-view></div> 
</body>
</html>
<div ng-controller = "TestCtrl">
    <h1>{{title}}</h1>
    <input class = "calculation-input" ng-model = "number1" placeholder = "Enter first number" id = "first" type = "text">
    <br>
    <input class = "calculation-input" ng-model = "number2" placeholder = "Enter second number" id = "second" type = "text">
    <br>
    <input ng-keypress = "calculate()" class = "calculation-input" ng-model = "operation" placeholder = "Enter an arithmetic operation here" id = "op" type = "text">
    <br>
    <input ng-click = "calculate()" type = "submit" value = "Submit" id = "calc">
    <br>
    <span id = "calculation">{{number1}}{{operation}}{{number2}}</span>
</div>

angular.html

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-route.js"></script>
    <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script>
    <script src = "student.js" type="text/javascript"></script>
    <script src = "testCtrl.js" type="text/javascript"></script>
    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
    <link href = "angular.css" rel = "stylesheet">
</head>
<body ng-app = "testing">
    <a href = "#/angular">Angular Calculator</a>
    <div ng-view></div> 
</body>
</html>
<div ng-controller = "TestCtrl">
    <h1>{{title}}</h1>
    <input class = "calculation-input" ng-model = "number1" placeholder = "Enter first number" id = "first" type = "text">
    <br>
    <input class = "calculation-input" ng-model = "number2" placeholder = "Enter second number" id = "second" type = "text">
    <br>
    <input ng-keypress = "calculate()" class = "calculation-input" ng-model = "operation" placeholder = "Enter an arithmetic operation here" id = "op" type = "text">
    <br>
    <input ng-click = "calculate()" type = "submit" value = "Submit" id = "calc">
    <br>
    <span id = "calculation">{{number1}}{{operation}}{{number2}}</span>
</div>

{{title}}




{{number1}}{{operation}{{number2}}
当我执行
angular.module('testing',[])时,它起作用了。
不确定您的意思,因为
angular.module('testing',[])
不会注入您的依赖项。你是说你遵循了我上面的答案还是其他什么?出于某种原因,当我遵循答案时,我仍然得到了错误。当我添加[]时,错误消失了,但是ng视图没有加载。添加
[]
只会覆盖第一个声明的模块,这就是为什么您没有看到加载的
ng视图的原因
[]
。由于另一个问题,错误仍然存在。看看我刚才对答案的更新。