I am looking to compare two dates in ng-if this is what my jade file looks like.
html :
<button ng-if="{{product.experationDate}} < {{CurrentDate}}" type="button>
// do somthing
</button>
javascript :
$scope.CurrentDate = new Date();
and : date_expiration: {type: Date}
but it not work ! any help will be appreciated. thanks
Don't do this kind of logic in the template. That's what your services and controllers are for. You need to have a method in your controller that returns the boolean:
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();
}
And your template:
ng-if="vm.isExpirationExpired(product)"
You can try with:
<button ng-if="product.experationDate < CurrentDate" type="button>
// do somthing
</button>
In Angular directives like ng-if, you don't need the {{ }} as the expression is evaluate either way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With