hjm
hjm

Reputation: 1953

Angular 1.5 Expected array but received: 0 when using filter

I'm creating a table, it works fine when I display data, this is the code

<tr ng-repeat="value in sd.data track by $index | orderBy: syscode">
  <td>{{($index>0 && sd.data[$index].syscode === sd.data[$index-1].syscode) ? '' : value.syscode}}</td>
  <td>{{value.out_signal_id}}</td>
  <td class="text-center no-wrapping">{{value.sig_epoch_utc}}</td>
  <td class="text-center ">{{value.num_of_signals}}</td>
  <td class="text-center no-wrapping">{{value.status_code}}</td>
  <td class="text-center no-wrapping">{{value.status_note}}</td>


 <tr >

My issue is that when I use 'orderBy:' as a filter, I get this error

`Error: [orderBy:notarray] Expected array` but received: 0

I am not sure why, I have checked other questions similar to this, but those didn't answer my question. Any feedback will be appreciated thanks

Upvotes: 1

Views: 602

Answers (2)

quirimmo
quirimmo

Reputation: 9998

Track by should be always at the end and you miss apices so this:

<tr ng-repeat="value in sd.data track by $index | orderBy: syscode">

should be:

<tr ng-repeat="value in sd.data | orderBy: 'syscode' track by $index">

Upvotes: 3

Matthew Green
Matthew Green

Reputation: 10401

This exact scenario is covered in the docs for ngRepeat (see the note at the bottom of the section). Basically, the track by needs to be the last thing in your expression.

value in sd.data | orderBy: 'syscode' track by $index

Upvotes: 1

Related Questions