我正在使用angularjs过滤器,但一切正常,但是当我寻找一个薪水为30(仅作为示例)的人时,它不起作用,如果我再增加一个值,它就开始起作用了,有人可以向我解释什么错了吗?用它?
柱塞链接https://plnkr.co/edit/bCz8jq8KSd7XCk2WmHo1?p=info
<!DOCTYPE html>
<html lang="en" ng-app="myModule">
<head>
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.9/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="myController">
Rows to display : <input type="number" step="1" ng-model="rowLimit" max="5" min="0" />
Sort By :
<select ng-model="sortColumn">
<option value="name">Name ASC</option>
<option value="+dateOfBirth">Date of Birth ASC</option>
<option value="+gender">Gender ASC</option>
<option value="-salary">Salary DESC</option>
</select>
Search : <input type="text" placeholder="Search employees" ng-model="searchText" />
<!-- Search : <input type="text" placeholder="Search employees" ng-model="searchText.city"/> -->
Hide Salary: <input type="checkbox" ng-model="hideSalary" />
<table>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Date Of Birth</th>
<th>Gender</th>
<th>Salary(number)</th>
<th ng-hide="hideSalary">Salary(currency)</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in emp|limitTo:rowLimit|orderBy:sortColumn | filter : searchText">
<!-- <tr ng-repeat="employee in emp|limitTo:rowLimit|orderBy:'-firstName'"> -->
<td>{{employee.firstName | uppercase}}</td>
<td>{{employee.lastName}}</td>
<td>{{employee.DOB | date:"dd-MM-yyyy"}}</td>
<td>{{employee.gender |lowercase}}</td>
<td>{{employee.salary|number:2}}</td>
<td>{{employee.salary|currency:'$'}}</td>
</tr>
</tbody>
</table>
</body>
</html>
**script.js**
var myApp = angular.module('myModule', []).controller("myController", function ($scope) {
var emp = [
{firstName:"Ben",lastName:"Ding",DOB:new Date('December 26, 1991'),gender:"Male",salary:500},
{firstName:"John",lastName:"Deo",DOB:new Date('December 26, 1991'),gender:"Male",salary:6500.21},
{firstName:"Rajesh",lastName:"kumar",DOB:new Date('December 26, 1991'),gender:"Male",salary:3500},
{firstName:"Rashmi",lastName:"singh",DOB:new Date('December 26, 1991'),gender:"female",salary:8500.78},
{firstName:"soumya",lastName:"kumari",DOB:new Date('December 26, 1991'),gender:"female",salary:30}
]
$scope.emp = emp;
$scope.rowLimit = 5;
$scope.sortColumn = name;
});
未应用过滤器的DOB值为“ 1991-12-25T18:30:00.000Z”,其中包含30。这就是未应用过滤器的原因。您可以将薪水30更改为其他任何数字,然后尝试使用,这样就可以了。日期值将根据当前日期和时间而更改。