I updated Angular on my project, from 1.4.9 to 1.5.3. And on one of the pages I'm getting this error message:
'Error: orderBy:notarray Value is not array-like', 'Expected array but received: 0'
Here is template:
<tr ng-repeat="targeting in vm.TargetingsAudience track by $index | orderBy:orderByName">
<td>
{{targeting.Name}}
</td>
<td class="au_content_descr">
<p ng-repeat="val in targeting.Values track by $index | orderBy:orderByName" class="targeting-value">{{val}}</p>
</td>
<td class="au_ico_2">
<a class="au_del au_fast_ico" ng-click="vm.removeTargeting(targeting)"><i class="glyphicon glyphicon-remove"></i></a>
<a class="au_edit au_fast_ico" ng-click="vm.editTargeting(targeting)"><i class="glyphicon glyphicon-pencil"></i></a>
</td>
</tr>
vm.TargetingsAudience - is an Array of Objects:
[{Name: "Гео", TargetingCategory: "Audience", TypeId:"Location", Values: [0: "Россия", 1: "Москва", 2: "Московская область"]}]
An orderBy Filter in AngularJS is used to sort the given array to the specific order. The default order of sorting the string is in alphabetical order whereas the numbers are numerically sorted. By default, all the items are sorted in ascending order, if the ordering sequence is not specified.
To sort in descending order, set it as true . You can also use + to sort the data in an ascending and – the data in descending order also . Here with the filters in Angular JS, instead of displaying the various rows, we will be sorting it by ascending and descending order .
Track by $index in AngularJS The ngRepeat track by $index allows you to specify which items should be repeated using their index number. The ngRepeat is a directive that can be added to the HTML template of an Angular application. It is used for creating lists, and it can take an expression as an argument.
This might be related to a breaking change in angular 1.5
Filters (orderBy)
Due to 2a85a634, passing a non-array-like value (other than undefined or null) through the orderBy filter will throw an error. Previously, the input was returned unchanged, which could lead to hard-to-spot bugs and was not consistent with other filters (e.g. filter). Objects considered array-like include: arrays, array subclasses, strings, NodeLists, jqLite/jQuery collections
Try using AngularJS toArray Filter
EDIT :
Because you sad you upgraded the app, I assumed it was working before. But to make it working I think you have to switch track by and order by statements
Note: track by must always be the last expression:
<tr ng-repeat="targeting in vm.TargetingsAudience | orderBy:orderByName track by $index ">
<p ng-repeat="val in targeting.Values | orderBy:orderByName track by $index " class="targeting-value">{{val}}</p>
Change orderBy:orderByName
to orderBy:'Name'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With