2016-03-29 11 views
0

AngularJS ile veriyi zaman uyumsuz olarak döndürecek bir hizmeti çağırmak için durum bilgisi olan bir filtre oluşturmaya çalışıyorum. Bunu test etmek için sadece string.logs dizesini içeren basit bir $ timeout fonksiyonunu kullanıyorum. Ancak, bu console.log sadece sonsuza kadar çalışıyor.

export default angular.module('components.filters.combine-name', []) 

.filter('combineName', ['$timeout', function ($timeout) { 
    function combineName(input) { 
    $timeout(function() { 
     console.log('test'); 
    }, 1000); 
    return input.firstName + ' ' + input.lastName; 
    } 

    combineName.$stateful = true; 
    return combineName; 
}]); 

html

<table class="table table-bordered table-striped table-responsive"> 
    <thead> 
    <tr> 
     <th> 
     <div class="th"> 
      Name 
     </div> 
     </th> 
     <th> 
     <div class="th"> 
      Status 
     </div> 
     </th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr ng-repeat="result in vm.results"> 
     <td>{{result | combineName}}</td> 
     <td>{{result.status}}</td> 
    </tr> 
    </tbody> 
</table> 

kontrolör: $ zamanaşımı

this.results = [ 
    { 
    firstName: 'Johnny', 
    lastName: 'Utah', 
    status: 'Active' 
    }, 
    { 
    firstName: 'Richard', 
    lastName: 'Reynolds', 
    status: 'Inactive' 
    }, 
    { 
    firstName: 'Randy', 
    lastName: 'Johnson', 
    status: 'Active' 
    } 
]; 
+0

$ timeout tetikleyicileri sindirir, filtre her sindirmeyi çalıştırır ... thats sonsuz döngü –

cevap

0

, temelde döngü açmak ve durmak yapmasını istemedikçe o kadar yapmaya devam edeceğiz.

Döngüsüz kullanımda: $ timeout.cancel();