Angular.js: 13236 Error: [orderBy: notarray] Expected array, but received:

This HTML suggests a click button:

<p><button class="btn btn-info" ng-click="ResetEventStation()">
    Choose a different station</button></p>

      

What calls this function:

$scope.ResetEventStation = function() 
{
    localStorage.removeItem("stationId");
    localStorage.removeItem("stationName");
    localStorage.removeItem("isRegistrationStation");

    $scope.stationId = -1;
    $scope.stationName = '';
    $scope.isRegistrationStation = false;
}

      

I can stop and take one step through the function, but when I step outside the closing parenthesis, I get

angular.js: 13236 Error: [orderBy: notarray] Expected array but received: {"customer_id": 97, "event_id": 6, "station_id": 7, "station_name": "St. Pancras", "customer_name" : "mawg", "event_title": "Event 1", "token": "20000097-6ee02241-7231-4f8d-9956-5cf5022de147"}      http://errors.angularjs.org/1.5.0/orderBy/notarray? p0 =% 7B% 22customer_id% 22%...% 22% 2C% 22token% 22% 3A% 2220000097-6ee02241-7231-4f8d-9956-5cf5022de147% 22% 7D with angular.js: 68 in angular.js: 20410 with fn (eval when compiling (angular. js: 14086),: 4: 200) at regularInterceptedExpression (angular.js: 15213) in Scope. $ digest (angular.js: 16655) in ChildScope app. $ apply (angular.js: 16928) on HTMLButtonElement. (angular.js: 24551) in HTMLButtonElement.dispatch (jquery-2.1.1.min.js: 3) in HTMLButtonElement.r.handle (jquery-2.1.1.min.js: 3)

Googling shows that this is a filter error and of course the browser console shows this function which I assume Angular for me:

(function($filter,ensureSafeMemberName,ensureSafeObject,ensureSafeFunction,getStringValue,ensureSafeAssignContext,ifDefined,plus,text
/*``*/) {
"use strict";
var fn=function(s,l,a,i){var v0,v1,v2,v3=l&&('ResetEventStation' in l);v2=v3?l:s;if(!(v3)){if(s){v1=s.ResetEventStation;}}else{v1=l.ResetEventStation;}ensureSafeObject(v1,text);if(v1!=null){ensureSafeFunction(v1,text);v0=ensureSafeObject(v2.ResetEventStation(),text);}else{v0=undefined;}return v0;};return fn;
})

      

I really don't understand what's going on. Can someone tell me what I am doing wrong and how to fix the error?

I can see it is {"customer_id":97,"event_id":6,"station_id":7,"station_name":"St. Pancras","customer_name":"mawg","event_title":"Event one","token":"20000097-6ee02241-7231-4f8d-9956-5cf5022de147"}

not an array, but not sure why it is being referenced.

+3


source to share


1 answer


You have to search your code for a filter orderBy

and modify / remove it. As it tries to sort the array, but instead of the array, you have this object.

There are two possible ways to use this filter:



  • First, in HTML, using ng-repeat="something in someArray | orderBy: some"

  • And in your AngularJS code with $filter('orderBy')(...)

Find them and change them to have an array instead (or remove the filter) to get rid of this error!

+1


source







All Articles