我是angularJs的初学者,我有这个简单而且可能很愚蠢的问题,无法连接简单的控制器来查看:
<!DOCTYPE html>
<html ng-app>
<head>
<title></title>
</head>
<body>
<div ng-controller="SimpleController">
NAME:
<input type="text" name="name" ng-model="name" />
<br/>
<ul>
<li ng-repeat="cust in customers | filter:name | orderBy:'city'">{{cust.name | uppercase}} - {{cust.city}}</li>
</ul>
</div>
<script src="js/angular.min.js" type="text/javascript"></script>
<script>
function SimpleController($scope){
$scope.customers=[{name:'Amelie',city:'Tbilisi'},{name:'Jani', city:'New York'}];
}
</script>
</body>
</html>
那么,任何人都可以解释我做错了吗?
答案 0 :(得分:1)
从angular vs 1.3.x
开始,您必须将控制器与模块绑定才能使用。
喜欢这个
angular
.module("app",[])
.controller("SimpleController",function($scope){
$scope.customers=[{name:'Amelie',city:'Tbilisi'},{name:'Jani', city:'New York'}];
})
在html中添加模块名称
<html ng-app="app">
的 JSFIDDLE 强>
答案 1 :(得分:1)
首先,您没有在页面中引用angularjs脚本。
然后取决于你的Angular版本(&gt; = 1.3),你必须创建一个模块并在里面注册控制器。
<html data-ng-app="myApp">
th[colspan="1"]
th[rowspan="4"]
th[colspan="1"]:nth-of-type(2)