cyberfly
6/2/2017 - 4:23 AM

Time ago with Moment and AngularJS

Time ago with Moment and AngularJS

<table class="table table-inbox table-hover">
                            <tbody>
                              <tr class="unread" ng-repeat="discussion in discussions">
                                  <td class="view-message text-right" ng-init="timeago = vm.timeAgo(discussion.updated_at.date)" >{{ timeago }}</td>
                              </tr>
                            </tbody>
                          </table>
DiscussionController.$inject = ['$rootScope', '$scope', '$stateParams','userService','$timeout','discussionService','$uibModal', '$state', 'localStorageService', 'evalService'];

    function DiscussionController($rootScope, $scope, $stateParams, userService, $timeout, discussionService, $uibModal, $state, localStorageService, evalService) {
        var vm = this;

        vm.timeAgo = timeAgo;

        //convert date with moment

        function timeAgo(date){
            var time_ago = moment(date).fromNow();
            return time_ago;       
        }
    }