我们正在对敲除和角度进行比较,以帮助确定哪个用于绑定。由于我不是当前的开发人员,我只是想把一个简单的单个html页面(index.html)放在一起,没有多个视图来进行这种比较。为了实现这一点,我查看了一个简单的jsfiddle关于敲门hello world示例,从页面复制源,将其粘贴到index.html中,更改了脚本引用路径,并提供了它。没问题我能够在单个文件中开始使用淘汰应用程序来开始测试。
尝试用Angular做同样的事情,我不断收到错误让我不确定问题是什么。这是一个例子。谁能告诉我我做错了什么? jsfiddle示例是:http://jsfiddle.net/Hp4W7/637/
这是代码。错误如下。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Scroll + limitTo - jsFiddle demo</title>
<script type='text/javascript' src='scripts/angular.js'></script>
<script type='text/javascript'>//<![CDATA[
var app = angular.module('app', []);
function Ctrl($scope) {
$scope.tasks = [{id:1,'name':'test1'}, {id:2,'name':'test2'}, {id:3,'name':'test3'}];
$scope.removeTask = function(taskId){
alert("Task Id is "+taskId);
};
}
//]]>
</script>
</head>
<body ng-app="app">
<div class="test" ng-controller="Ctrl">
<div ng-repeat="task in tasks">
<button ng-click="removeTask(task.id);">remove</button>
</div>
</div>
</body>
</html>
这是错误信息。
Error: [ng:areq] Argument 'Ctrl' is not a function, got undefined http://errors.angularjs.org/1.3.0-rc.5/ng/areq?p0=Ctrl&p1=not%20a%20function%2C%20got%20undefined at assertArg (http://myhost/angulartest/scripts/angular.js:1609:5) at assertArgFn (http://myhost/angulartest/scripts/angular.js:1619:3) at Anonymous function (http://myhost/angulartest/scripts/angular.js:8074:9) at Anonymous function (http://myhost/angulartest/scripts/angular.js:7251:13) at forEach (http://myhost/angulartest/scripts/angular.js:343:11) at nodeLinkFn (http://myhost/angulartest/scripts/angular.js:7238:11) at compositeLinkFn (http://myhost/angulartest/scripts/angular.js:6746:13) at compositeLinkFn (http://myhost/angulartest/scripts/angular.js:6749:13) at publicLinkFn (http://myhost/angulartest/scripts/angular.js:6625:30) at Anonymous function (http://myhost/angulartest/scripts/angular.js:1488:11)
答案 0 :(得分:3)
此问题与他们在AngularJS 1.3中所做的更改有关。
您可以通过此链接https://github.com/angular/angular.js/commit/3f2232b5a181512fac23775b1df4a6ebda67d018阅读更改。
这个想法是全局控制器形式非常糟糕,因此默认情况下禁用该选项。如果要启用该功能,则必须设置$controllerProvider.allowGlobals();
。否则你应该像下面那样设置你的控制器:
app.controller("Ctrl", ["$scope", function($scope) {
//Code
}]);
答案 1 :(得分:2)
一切正常,但控制器未正确注册。您需要执行以下操作:
var app = angular.module('app', []);
app.controller("Ctrl", function($scope)
{
// code..
});