我希望在 ng 中比较两个日期 - 如果这是我的玉文件的样子。
html :
<button ng-if="{{product.experationDate}} < {{CurrentDate}}" type="button>
// do somthing
</button>
Run Code Online (Sandbox Code Playgroud)
javascript :
$scope.CurrentDate = new Date();
Run Code Online (Sandbox Code Playgroud)
和 : date_expiration: {type: Date}
但它不起作用!任何帮助将不胜感激。谢谢
不要在模板中做这种逻辑。这就是您的服务和控制器的用途。您需要在控制器中有一个返回布尔值的方法:
isExpirationExpired(product) {
// your date logic here, recommend moment.js;
return moment(product.experationDate).isBefore(moment(currentdate));
// or without using moment.js:
return product.experationDate.getTime() < currentdate.getTime();
// or using Date
return new Date(product.experationDate).valueOf() < new Date(currentdate).valueOf();
}
Run Code Online (Sandbox Code Playgroud)
还有你的模板:
ng-if="vm.isExpirationExpired(product)"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12216 次 |
| 最近记录: |