"few seconds ago" and "a minute ago” text mismatches with the actual time given in angularjs

347 views Asked by At

In my web application, we have a requirement to display the time as "few seconds ago" and "few minutes ago" based on the time pulled from the back-end.

I am using the angular-moment and moment libraries.

The text being displayed for the "am-time-ago" directive of "angular-moment", like "few seconds ago, a minute ago" for the given time, is not matching. Here, sometimes the text changes to "a minute ago" even before the actual time is more than a minute ago.

Here is the plunker which reflects the issue mentioned.

angular.module('timeApp', ['angularMoment'])
.controller('mainController', function() {
  
  var vm = this;
  vm.time = new Date();//"2016-12-16 18:41:08";//new Date();
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-moment/0.9.0/angular-moment.min.js"></script>
<div class="container" ng-app="timeApp" ng-controller="mainController as main">
      <div>
        <h2>Displaying Time Relatively in Angular</h2>
        <p>The Time is {{ main.time }}</p>
        <div am-time-ago="main.time"></div>
      </div>
    </div>

0

There are 0 answers