如何使用 ng-if 在 angularJS 中实现检查空日期?
HTML源代码是
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<thead>
<tr>
<th>Name</th>
<th>D.O.B</th>
</tr>
</thead>
<tr ng-repeat="x in names>
<td>{{ x.Name }}</td>
<td><span ng-if="x.DOB != null">{{ formatDate(x.DOB) | date:'dd-MM-yyyy' }}</span></td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$scope.names = [
{ Name: 'Jani', DOB: '' },
{ Name: 'Hege', DOB: '1995-05-07' },
{ Name: 'Kai', DOB: '1995-08-24' }
];
$scope.formatDate = function (date) {
return new Date(date);
};
});
</script>
</body>
</html>
在这里,我希望使用 angularJS ng-if 消除日期值等于 null 或 NaN-NaN-0NaN
在上面的源代码中没有执行 IF 条件
最佳答案
您可以使用 ng-if="x.DOB"
因为空字符串或未定义将返回 false
关于angularjs - 如何使用 ng-if 实现在 angularJS 中检查空日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34153179/