比较html angularjs ionic

时间:2016-05-11 11:15:00

标签: javascript angularjs ionic-framework

所以基本上我有这个html文件显示通知消息列表,我希望能够知道每个通知的时间之间的差异,但不知道如何在html中执行此操作

<ion-item ng-repeat="single in notifications_list track by $index" class="ng-scope" ng-class="single.read == true ? 'notification-read' : 'notification-unread'" ng-click="displayNotification(single)" style="padding:13px 16px 1px;">
        <div class="notifications">
            <p style="white-space:normal;font-size:16px;line-height:20px;">{{single.body}}</p>
            {{(currentDate - single.time).getDays()}}
            <time>{{ single.time | amCalendar:referenceTime:formats }}</time>
        </div>
    </ion-item>

我已经在我的代码中创建了$rootScope.currentDate = new Date();

所以e.g. 2016-05-11T10:30:48.616Z - 2016-05-10T19:14:13.487+08:00这基本上就是我想在html视图中做的事情,并以天为单位返回差异。

我该怎么做?请指教

4 个答案:

答案 0 :(得分:0)

I think this will help you, time ago angularjs plugin allow to show the time in human readable firmat....for example like few time ago,,,,,hours ago,,,,etc

Link

答案 1 :(得分:0)

I see that you are using amCalendar, so I'm guessing you are already using the angular-moment plugin.

If so, you could use the amDifference filter

So I guess you could do something like:

<time>{{ single.time | amDifference : null : 'days' }}</time>

答案 2 :(得分:0)

使用use moment.js so Calculation on Dates and Times

<ion-item ng-repeat="single in notifications_list track by $index" class="ng-scope" ng-class="single.read == true ? 'notification-read' : 'notification-unread'" ng-click="displayNotification(single)" style="padding:13px 16px 1px;">
    <div class="notifications">
        <p style="white-space:normal;font-size:16px;line-height:20px;">{{single.body}}</p>
        {{getDiff(single.time)}}
        <time>{{ single.time | amCalendar:referenceTime:formats }}</time>
    </div>
</ion-item>
控制器中的

$scope.getDiff=function(time){
var now=moment();
return  now.diff(time, 'days') 
};

答案 3 :(得分:0)

您可以将angular-duration-format用于此目的。

添加角度持续时间格式作为您的应用依赖项。

angular.module('myModule', [
'angular-duration-format'
]);

在模板中,您可以使用

<p>
Time passed: {{ passed | duration:'hh:mm:ss:sss' }}<br/>
Preformatted: {{ passedPre }}
</p>

在控制器(或指令,服务,任何地方)

angular.module('myModule').controller('exampleCtrl', function($scope, $filter) {
var durationFilter = $filter('duration');

$scope.passed = 123456789;
$scope.passedPre = durationFilter($scope.passed, 'hh:mm:ss:sss');

});

两种情况下的结果应该相同:

Time passed: 34:17:36:789
Preformatted: 34:17:36:789