我想创建一个早上傍晚和下午重新出现的指令。如果我在java脚本中编码,这将是逻辑
var time = 00;
/* hour is before noon */
if ( time < 12 )
{
document.write("Good Morning!");
}
else /* Hour is from noon to 5pm (actually to 5:59 pm) */
if ( time >= 12 && time <= 17 )
{
document.write("Good Afternoon!");
}
else /* the hour is after 5pm, so it is between 6pm and midnight */
if ( time > 17 && time <= 24 )
{
document.write("Good Evening!");
}
else /* the hour is not between 0 and 24, so something is wrong */
{
document.write("I'm not sure what time it is!");
}
如何在角度使用指令
中实现此目的我的角度应用程序dom是
<p> 12:00:01 </p>
我希望它呈现为<p>afternoon </p>
答案 0 :(得分:2)
我更喜欢使用过滤器而不是指令,它的实现非常简单,如下所示。
过滤强>
app.filter('greet', function() {
return function(input) {
if (input < 12) {
return 'Good Morning';
} else if (input >= 12 && input <= 17) {
return 'Good Afternoon';
} else if (input > 17 && input <= 24) {
return 'Good Evening';
} else {
return "I'm not sure what time it is!";
}
};
});
HTML: <span>{{value | greet}}</span>