我是 AngularJS 的新手,并尝试让以下代码正常工作。
这实际上是 AngularJS 教程中的代码,稍加修改。我改变的是我将所有指令作为类而不是属性。
问题是 AngularJS 可以成功引导,并且可以计算表达式 {{ 1 + 2 }}。但 ng-controller 似乎无法被识别,并且以下 ng-repeat 也不起作用。
我检查了 AngularJS API 文档,它说 ng-controller 可以用作类。
任何有使用 AngularJS 指令作为类经验的人都可以帮助我吗?
ng-controller 作为类(不工作):http://jsfiddle.net/qZmky/
ng-controller 作为属性(工作): http://jsfiddle.net/p45Uv/
<html class="ng-app">
<p>Nothing here {{1 + 2}}</p>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.js"> </script>
<script>
function PhoneListCtrl($scope){
$scope.phones = [
{"name": "Nexus S","snippet": "Fast just got faster with Nexus S."},
{"name": "Motorola XOOM™ with Wi-Fi","snippet": "The Next, Next Generation tablet."},
{"name": "MOTOROLA XOOM™","snippet": "The Next, Next Generation tablet."}
];
}
</script>
</head>
<body class="ng-controller: PhoneListCtrl;">
<ul>
<li ng-repeat="phone in phones;">
{{phone.name}}
<p>{{phone.snippet}}</p>
</li>
</ul>
</body>
</html>
最佳答案
从AngularJS邮件列表得到答案,API文档实际上是错误的......
详细信息请引用以下内容:
关于angularjs - 如何在类属性中使用 AngularJS ng-controller 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14496474/