【发布时间】:2013-11-25 10:20:15
【问题描述】:
我有以下代码
angularDemo.html
<!DOCTYPE html>
<html data-ng-app="demoApp">
<head>
<title></title>
</head>
<body >
<div data-ng-view=""></div>
<script src="angular.min.js"></script>
<script>
var demoApp = angular.module('demoApp',[]);
demoApp.config(function($routeProvider){
$routeProvider
.when('/',
{
controller: 'SimpleController',
templateUrl: 'Partials/view1.html'
})
.when('/view2',
{
controller: 'SimpleController',
templateUrl: 'Partials/view2.html'
})
.otherwise({redirectTo:'/'});
});
demoApp.controller('SimpleController',function($scope){
$scope.customers = [{name:'Pranav', city:'Pune'},{name:'Yogi', city:'Banglore'},{name:'Ashish', city:'Malad'},{name:'Ritesh', city:'bangkok'}];
});
</script>
<div data-ng-controller="SimpleController">
</div>
</body>
</html>
Partials/view1.html
<!DOCTYPE html>
<html data-ng-app>
<head>
<title>View 1</title>
</head>
<body>
<div class='container'>
<input ng-model='name1' type='text'>
<p>{{name1}}, How is it going?</p>
<ul>
<li data-ng-repeat="cust in customers | filter:name1 | orderBy:'city'">{{cust.name | uppercase}} - {{cust.city | lowercase}}</li>
</ul>
<a href="#/view2">View 2</a>
</div>
</body>
</html>
Partials/view2.html
<!DOCTYPE html>
<html data-ng-app>
<head>
<title>View 2</title>
</head>
<body>
<div class='container'>
<input ng-model='city' type='text'>
<p>{{city}}, Its a Beautifull place to be.</p>
<ul>
<li data-ng-repeat="cust in customers | filter:city | orderBy:'city'">{{cust.name | uppercase}} - {{cust.city | lowercase}}</li>
</ul>
</div>
</body>
</html>
现在,每当我在输入中输入任何城市名称以过滤 view1 中的列表时,它都会被过滤,但根据功能,它应该只按客户名称过滤,反之亦然也在 view2.html 中发生
能否帮助我了解此过滤器属性是如何在这里工作的?
【问题讨论】:
标签: javascript angularjs angularjs-filter