M
M
Max2015-05-23 17:02:00
JavaScript
Max, 2015-05-23 17:02:00

Why is date not being compared in Angular.js?

Hello, I apologize for the possibly stupid question, but I'm not clear what the error is.
There is a JSON file from which I take the date. I wrote my own filter for it.
JSON entry example:

[
    {
        "productId": "milk", 
        "name": "Молоко", 
        "calories": "220 Ккал",
        "price": 12,
        "termin": 3,
        "data": "25.05.2015"
    },

Code in filter call:
<p>Дата изготовления: {{product.data | dateMark}} </p>

The filter itself:
productApp.filter('dateMark', function(){
  return function(srok){
    var nowDate = new Date;
    if (nowDate < srok){
      return 'Круто';
    } else 
      return 'НЕ круто';
  }
});

But everywhere it is written "NOT cool." That is, the date does not really compare.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Antonov, 2015-05-23
@maxprof

Well, and the data string does not need to be converted to a date?
Date.parse for what is given.

A
Alexander Tartmin, 2015-05-25
@baskerville42

Kosher to do this with moment.js

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question