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: "Московская область"]}]
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: "Московская область"]}]
Share
edited Apr 6, 2016 at 11:16
TaZz
6727 silver badges24 bronze badges
asked Apr 6, 2016 at 10:47
Максим ЛебидьМаксим Лебидь
811 silver badge3 bronze badges
2 Answers
Reset to default 11This 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'
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743667313a4487191.html
评论列表(0条)