學習使用angularJS,角度JS範圍變量不起作用
我在我的index.html中有這個特定的代碼。動態打字在上半部分起作用,但注射不起作用。什麼可能會出錯?
代碼:
<!DOCTYPE html>
<html>
<head>
<title>Test1</title>
</head>
<body ng-app="">
<!-- Dynamic Type -->
<input type="text" ng-model="name1" /><br>
<h1>Hello {{name1}}</h1>
<!-- End dynamic Type -->
<!-- Scope Injection begin-->
<div class="container" ng-controller="myController">
<input type="text" ng-model="naam" /><br>
<h3>Looping</h3>
<ul>
<li data-ng-repeat="cust in customerlist | filter:naam | orderBy:'city'"> {{cust.name | uppercase}} - {{cust.city}} </li>
</ul>
</div>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript">
function myController ($scope) {
$scope.customerlist = [
{name: 'Raj Bannerjee', city: 'Zaire'},
{name: 'Prasun Bannerjee', city: 'Udaipur'},
{name: 'Raj Malhotra', city: 'Dubai'},
{name: 'Prasun Joshi', city: 'Mumbai'}
];
}
</script>
</body>
</html>
你怎麼看它不工作?這是一個jsfiddle(略有修改),工作正常。 http://jsfiddle.net/b69p4zj9/ – deitch 2014-11-23 08:44:20
也許我看到它。你問過濾器是如何工作的? – deitch 2014-11-23 08:46:49
你需要告訴角度myController是一個控制器'angular.controller('myController',function($ scope){....' – 2014-11-23 09:08:23