我正在尝试将控制器连接到我的视图,并且我一直收到此错误:
错误:ng:areq Bad Argument参数'TestAppCtrl'不是函数, 未定义
我有这个观点:
<!DOCTYPE html>
<html ng-app lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Resume Page</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- ExtraCSS -->
<link rel="stylesheet" href="css/extra.css">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<!-- Angular -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
<!-- External JS extras -->
<script src="js/script.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body ng-app="app">
<div class="container">
<div class="row">
<h3>Resume</h3>
</div>
<div ng-controller="TestAppCtrl" id="TestAppCtrl">
{{data}}
</div>
<div class="row">
<div class="col-sm-6 col-xs-12 span4">
<h4>About</h4>
<div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#technical" aria-controls="technical" role="tab" data-toggle="tab">Technical</a></li>
<li role="presentation"><a href="#school" aria-controls="school" role="tab" data-toggle="tab">School</a></li>
<li role="presentation"><a href="#experience" aria-controls="experience" role="tab" data-toggle="tab">Experience</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="technical">
</div>
<div role="tabpanel" class="tab-pane" id="school">
.t..
</div>
<div role="tabpanel" class="tab-pane" id="experience">
.z..
</div>
</div>
</div>
</div>
<div class="col-sm-6 col-xs-12">
<h4>Contact Info</h4>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>
这个控制器: //由CoffeeScript 1.9.3生成 var app;
app = angular.module('app', []);
console.log("hello world");
app.controller('TestAppCtrl', ['$scope', function($scope) {
$scope.data = [1, 2, 3, 4, 5];
}]);
我知道它找到了正确的控制器,因为控制台日志会打印出来。但是控制器中的数据在视图中没有绑定,只是显示为{{data}}任何建议都会有很大帮助,谢谢。
答案 0 :(得分:1)
你有两次ng-app
<!DOCTYPE html>
<html ng-app lang="en">
...
</head>
<body ng-app="app">
Angular将使用页面上的第一个,您的初始化语句引用第二个ng-app
app = angular.module('app', []);