我正在阅读来自servcie的消息列表并以格式显示。我从servcie中获取的json数据是:
{"item": [
{
"createDtTm": "2015-12-04T15:24:16.094-06:00",
"folder": 1 ,
"from": "abc@test.com",
"itemId": "41",
"itemType":"MESSAGE"
"read": "true",
"subject": "Here is a test message",
"toDirectAddress": "xyz@test.com"
},
{
"createDtTm": "2015-12-07T15:24:16.094-06:00",
"folder": 1,
"from": "abc@test.com",
"itemId": "41",
"itemType":"MESSAGE"
"read": "true",
"subject": "Here is a test message",
"toDirectAddress": "xyz@test.com"
},
{
"createDtTm": "2015-12-05T15:24:16.094-06:00",
"folder": 1,
"from": "abc@test.com",
"itemId": "41",
"itemType":"MESSAGE"
"read": "true",
"subject": "Here is a test message",
"toDirectAddress": "xyz@test.com"
}
]}
使用这些数据,我试图在一个视图中显示,具有今天日期的消息,在Todays下,昨天的昨天消息,类似于它在outlook电子邮件中的显示方式。如何在角度js中以该格式显示?
Today
msg1 6:00PM
msg2 5.00AM
yesterday
msg3
msg4
one week ago
msg4
这是我的服务电话:
var promise = $http.post(urlBase + '/' + 'getData')
.success(function(data){
dataList = data;
return dataList ;
})
.error(function(data){
dataList= 'error';
return dataList;
});
return promise;
},
这是我的控制器方法:
$scope.dataList = function(){
return Service.getData();
}
答案 0 :(得分:0)
答案 1 :(得分:0)
在视图模板(html)上试试这个
<div ng-show="{{dataList != 'error'}}" ng-repeat="message in dataList | orderby : message.createDtTm ">
<div>
{{message.createDtTm | myDateFilter }}
message.subject
</div>
</div>
你应用中的注册了一个名为myDateFilter的过滤器
yourApp.filter('myDateFilter', function(){
return function(input){
var today = new Date();
var result = null;
var val = null;
if(input)
{
val = new Date();
}
else
{
val = new Date(input);
}
if(val.getTime() < date.getTime())
{
result = "Yesterday";
}
else if(val.getTime() == date.get)
{
result = "Today";
}
else
{
//SO on your date logic
}
return result;
}
});