在此代码中,我没有获得无序的客户列表或城市名称
<!DOCTYPE html>
<html data-ng-app="">
<head>
<title>Using AngularJS Directives and Data Binding </title>
</head>
<body data-ng-init="customers=[{name:'Rishabh Shrivas',city:'New Delhi'},{name:'Rishabh Bharadawaj',city:'Noida'},{name:'Rishabh Sen ,city:'Gurgaon'}] ">
Name :
<br />
<input type="text" data-ng-model="name" placeholder="Enter Your Name " /> {{ name }}
<br />
<ul>
<li data-ng-repeat="cust in customers | filter:{name} "> {{ cust.name }} - {{ cust.city }} </li>
</ul>
<script src="Scripts/angular.min.js"></script>
</body>
</html>
答案 0 :(得分:0)
您在ng-init中缺少'并且在过滤器中不使用{}。
<body data-ng-init="customers=[{name:'Rishabh Shrivas',city:'New Delhi'},{name:'Rishabh Bharadawaj',city:'Noida'},{name:'Rishabh Sen' ,city:'Gurgaon'}]">
Name :
<br />
<input type="text" data-ng-model="name" placeholder="Enter Your Name " /> {{ name }}
<br />
<ul>
<li data-ng-repeat="cust in customers | filter:name "> {{ cust.name }} - {{ cust.city }} </li>
</ul>
</body>
答案 1 :(得分:0)
检查一下
您的过滤器应该是这样的
data-ng-repeat="cust in customers | filter:name "
更新的HTML:
<body data-ng-init="customers=[{name:'Rishabh Shrivas',city:'New Delhi'},{name:'Rishabh Bharadawaj',city:'Noida'},{name:'Rishabh Sen' ,city:'Gurgaon'}] ">
Name :
<br />
<input type="text" data-ng-model="name" placeholder="Enter Your Name " /> {{ name }}
<br />
<ul>
<li data-ng-repeat="cust in customers | filter:name "> {{ cust.name }} - {{ cust.city }} </li>
</ul>
</body>