0
AngularJSでステートフルフィルタを作成して、最終的にデータを非同期に返すサービスを呼び出そうとしています。これをテストするには、単純な$ timeout関数を使用しています。これはconsole.logsという文字列です。ただし、このconsole.logは無限に実行されています。
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>
コントローラ:$タイムアウトで
this.results = [
{
firstName: 'Johnny',
lastName: 'Utah',
status: 'Active'
},
{
firstName: 'Richard',
lastName: 'Reynolds',
status: 'Inactive'
},
{
firstName: 'Randy',
lastName: 'Johnson',
status: 'Active'
}
];
$ timeoutはダイジェストをトリガーし、フィルターは各ダイジェストを実行します... thats無限ループ –