我是AngularJS的新手,並且有一個簡單控制器的問題。任何人都可以幫助我嗎?我不明白爲什麼SimpleController
在這裏不起作用! 我需要在字段後面顯示文本框的輸入,如{{name}}
所示。 基本上,它應該產生一個客戶名單SimpleController' where this list should be filtered by
名稱and ordered by
budget` ... 但它不! 下面是HTML和JS代碼:無法找出這個簡單的角度控制器的問題
<html ng-app="">
<head>
<title>My Angular with Simple Controller</title>
</head>
<body>
<div ng-controller="SimpleController">
Name:
<br />
<input type="text" ng-model="name" /> {{name}}
<br />
<h3> Looping with ng-repeat & SimpleController</h3>
<ul>
<li ng-repeat="cust in customers | filter:name | orderBy:'budget'">
{{cust.name}} - {{cust.city}} - {{cust.budget}}
</li>
</ul>
</div>
<script src="angular.min.js"></script>
<script>
function SimpleController($scope) {
$scope.customers = [
{name: 'AAA', city:'cityAAA', budget:'500'},
{name: 'BBB', city:'cityBBB', budget:'5000'},
{name: 'ABC', city:'cityABC', budget:'6000'},
];
}
</script>
</body>
</html>
方案工作得很好,而無需使用控制器(通過僅使用ng-init
)當添加角模塊
什麼引發錯誤? Angular在版本1.3中不再支持全局函數作爲控制器。你使用什麼版本? – charlietfl
我不認爲會引發任何錯誤...但所需的輸出不顯示!我目前的版本是AngularJS v1.5.8 –
請按照文檔創建模塊和註冊控制器,並與ng-app – charlietfl