Answer the question
In order to leave comments, you need to log in
How to recolor Label?
Hello, I have this JS code:
productApp.filter('dateMark', function(){
return function(srok, TERMIN){
var nowDate = new Date;
console.log(srok);
if (Date.parse(nowDate) < ( Date.parse(srok) + ((86400000 * TERMIN)))){
return 'Свежий товар';
}
else if (Date.parse(nowDate) > ( Date.parse(srok) + ((86400000 * TERMIN)))){
return 'Термин хранения кончается';
}
else return 'Ошибка';
}
});
<span class="label label-success" >Дата изготовления: {{product.data | dateMark : product.termin}} </span>
else if (Date.parse(nowDate) > ( Date.parse(srok) + ((86400000 * TERMIN)))){
return 'Термин хранения кончается';
Answer the question
In order to leave comments, you need to log in
The simplest and "clumsy" option:
productApp.filter('dateMark', function(){
return function(srok, TERMIN){
var nowDate = new Date;
console.log(srok);
if (Date.parse(nowDate) < ( Date.parse(srok) + ((86400000 * TERMIN)))){
return {text:'Свежий товар', class: 'label label-success'};
}
else if (Date.parse(nowDate) > ( Date.parse(srok) + ((86400000 * TERMIN)))){
return {text:'Термин хранения кончается', class: 'label label-error'};
}
else return 'Ошибка';
}
})
In order not to suffer as much with the simplicity of the date as you do, take a look at moment.js. An excellent library in which you can twirl with dates as you like.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question