2016-03-21 11 views
0

jsonからデータ(日付)を取得し、それらを表示するためにng-repeatを使用しましたが、momentjsを使用して日付の新しいフォーマットを設定します。私の問題は、私のフォーマットを設定するために私のコントローラの "item.date"から値を取得する方法を知らないということです。ここに私のコードは次のとおりです。コントローラの日付をng-repeat角度から取得する

コントローラ:

.controller('RegistreCtrl', function ($scope, $stateParams,factotransaction) { 
    console.log("coucou"); 
    var mytoken = sessionStorage.getItem('token'); 
    factotransaction.send(mytoken).then(function(conf){ 
    console.log(conf); 
      $scope.datab = conf.data; 

    }) 

}) 

ビュー:

<ion-view view-title="Registre"> 
    <ion-content> 
    <h1>Registre</h1> 
    <ul class="list" ng-repeat="item in datab track by $index"> 

     <li class="item" ng-repeat="mytitle in item.assignation"> 
     {{item.date}} 

      {{mytitle.category}}{{mytitle.amount}} 
     </li> 
    </ul> 
    </ion-content> 
</ion-view> 

JSON:

enter image description here

答えて

1

あなたがいるそのうちの2つの可能性のカップルを、持っていますディレクティブを使用してitemを処理することができます。あなたが望むものなら何でもあなたのデータを使って行うことができます。

<item data="item" ng-repeat="item in datab track by $index"></item> 

ような何か
.directive('item', function(){ 
    controller: function($scope){ 
     // do stuff with $scope.item 
    }, 
    scope: { 
     item: '=data' 
    } 
}); 

また、あなたは唯一の特定の方法で日付を表示したい特別な場合は、フィルタを使用して日付のものを行うことができます。

{{item.date | myDate}} 

.filter('myDate', function(){ 
    return function(date){ 
     // do stuff with the date 
     return formattedDate; 
    } 
}); 
+0

大きな説明thanks a loそれは非常に有用だった:) – xenurs

関連する問題