gpt4 book ai didi

javascript - 将 Angular Controller 连接到 View 时出现问题

转载 作者:行者123 更新时间:2023-12-03 09:36:55 25 4
gpt4 key购买 nike

我正在尝试将 Controller 连接到我的 View ,但不断收到此错误:

Error: ng:areq Bad Argument Argument 'TestAppCtrl' is not a function, got undefined

我有这样的观点:

<!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>

这个 Controller ://由 CoffeeScript 1.9.3 生成 var 应用程序;

app = angular.module('app', []);

console.log("hello world");

app.controller('TestAppCtrl', ['$scope', function($scope) {
$scope.data = [1, 2, 3, 4, 5];
}]);

我知道它正在找到正确的 Controller ,因为控制台日志会打印。但是 Controller 中的数据并未在 View 中绑定(bind),它只是显示为 {{data}} 任何建议都会有很大帮助,谢谢。

最佳答案

你有两次 ng-app

<!DOCTYPE html>
<html ng-app lang="en">
...
</head>
<body ng-app="app">

Angular 将使用页面上的第一个,您的初始化语句引用第二个 ng-app

app = angular.module('app', []);

关于javascript - 将 Angular Controller 连接到 View 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31308568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com