2016-05-02 14 views
2

我有一個Angularjs應用程序。在應用程序中,我有一個表格,通過ng-repeat和API連接顯示數據。這意味着我通過控制器中的API連接獲取信息。 其中一個數據項是「日期和時間」。 當我使用ng-repeat時,我會顯示數據庫中的日期,但我想將其顯示爲倒計時,而不是完全像數據庫中那樣。使用ng-repeat和API連接創建AngularJS倒數

下面是HTML代碼:

<tbody> 
     <tr class="info" id="{{$index}}" ng-repeat="matches in future_match"> 
      <td style="text-align: center;"> 
      <img src="asset/images/loltables.png"></td> 
      <td style="font-weight:bold;">{{matches.matche_title}} - Best Of {{matches.matche_bestOf}} 
      <br></br> <center><img ng-src="{{matches.competitors.0.c_img}}" style="padding-right: 30px; padding-bottom: 15px;"/><img ng-src="{{matches.competitors.1.c_img}}" style="padding-bottom: 15px;"/><br>{{matches.competitors.0.c_short_name}}&nbsp;&nbsp; <b>vs.</b> &nbsp;&nbsp;{{matches.competitors.1.c_short_name}}</center></td> 
      <td style="text-align: center;"><i class="fa fa-dollar" style="color:green;"></i>50&nbsp;</td> 
      <td style="text-align: center;">50</td> 
      <td style="text-align: center;">{{matches.matche_start}}</td> 
      <td style="text-align: center;"><button type="button" data-toggle="modal" data-target="#ava_gold" ng-click="select(matches)" class="btn btn-info btn-circle">Enter</button></td> 
     </tr> 
    </tbody> 

只想將其顯示爲倒計時並且不喜歡它是在數據庫中,其是2015年12月3日 10:00:00 GTM

我是Angularjs的新手,所以我需要它簡單易用。

感謝

走在這個
+0

瞬間JS還提供了這一點::比你能在HTML頁面中使用常規管道語法使用https://github.com/urish/angular-moment#am-time-ago-directive您CA n總是看看他們如何在源代碼中執行它... –

回答

1

一種方法是創建一個自定義filter,例如:

​​

的自定義過濾器應放在配置文件(可能app.js)中,並

<td style="text-align: center;">{{ matches.matche_start | countdown }}</td> 
+0

謝謝。對白癡問題抱歉,但我如何將它添加到我的main.js?作爲什麼?我在那裏有我的國家和指令。就是它 – Lee

+0

在我的例子中,應用程序名稱是'yourApp',所以我在main.js中通過調用'angular.module('yourApp',[])''然後通過調用'添加一個過濾器來獲得應用程序。 filter'。如果你將你的應用程序對象設置爲一個變量,那麼只需在該變量上調用'.filter'。 – OzW

+0

我試過但我得到錯誤。我的main.js有連接到它的狀態和其他控制器。所以我不知道在哪裏添加它。這裏:angular.module('Authentication',[]); angular.module('app',[]); angular.module('DashController',[]); angular.module('AppController',[]); angular.module('LayoutHorizo​​ntalMenuController',[]); angular.module('PageLiveController',[]); – Lee