我是AngularJS的新手,刚刚开始做一些事情,
我有一个非常基本的疑问,
节目编号:1
<body data-ng-app data-ng-init="nodes=[{name: 'T', age: 25},{name: 'A', age: 26},{name: 'R', age:27}]">
<div />
Filter of the data : {{names}}
<br>
<input type="text" data-ng-model="filtername"> {{filtername}}
<br>
<hr>
<ul>
<li data-ng-repeat="node in nodes| orderBy: 'name' | filter: filtername">{{node.name|uppercase}} - {{node.age}}</li>
</ul>
<script type="text/javascript" src="scripts/angular/angular.js"></script>
</body>
该程序以应有的方式使用过滤器。
节目编号:2
<div data-ng-controller="Controller_Contact_View">
Name:<input type="text" data-ng-model="name" />
Email:<input type="text" data-ng-model="email" />
<button data-ng-click="add()">Add</button>
<hr>
Search on Name:<input type="text" data-ng-model="searchName" />{{searchName}}
<h2>Contacts</h2>
<ul>
<li data-ng-repeat="contact in contacts| orderBy: 'getName()'| filter: searchName"><b>{{ contact.getName() }}</b> - <a href="mailto:{{contact.getEmail()}}">{{contact.getEmail()}}</a></li>
</ul>
</div>
<script type="text/javascript" src="scripts/angular/angular.js"></script>
<script>
function Controller_Contact_View($scope) {
$scope.contacts = new Array();
//var contacts = ;\
var c = new Contact('A', 'email_' + 12 + '@pkrm.com');
$scope.contacts.push(c);
c = new Contact('R', 'email_' + 1 + '@pkrm.com');
$scope.contacts.push(c);
c = new Contact('V', 'email_' + 41 + '@pkrm.com');
$scope.contacts.push(c);
c = new Contact('T', 'email_' + 11 + '@pkrm.com');
$scope.contacts.push(c);
c = new Contact('K', 'email_' + 10 + '@pkrm.com');
$scope.contacts.push(c);
$scope.add= function(){
var n = $scope.name;
var e = $scope.email;
var c = new Contact(n, e);
$scope.contacts.push(c);
$scope.name = $scope.email = "";
};
}
</script>
<script>
var Contact = function(name, email){
this.name = name;
this.email = email;
return({
getName : function(){
return name;
},
getEmail : function(){
return email;
},
setName : function(n){
name = n;
},
setEmail : function(e){
email = e;
}
});
};
</script>
它们都是相同的,但过滤器在第 2 号程序中不起作用
求大神指点一下,问题出在哪里