angularjs ngRepeat orderBy when property key has spaces angularjs ngRepeat orderBy when property key has spaces angularjs angularjs

angularjs ngRepeat orderBy when property key has spaces


Simplest way, just surround a field name with UTF8 code for quotation mark:

HTML

<li ng-repeat="item in items | orderBy:'\u0022Spaced Key\u0022'">

JS

$scope.orderKey = '\u0022Spaced Key\u0022';


Comments appeared to help so I'm including it as an answer:

One way to sort items with spaces in their object property names is to pass a predicate sort function into orderBy instead of specifying the object property name. The relevant modifications in particular:

HTML:

<li ng-repeat="credit in credits | orderBy:predicate">

JS:

$scope.predicate = function(val) {  // $scope.corder corresponds to the object property name to sort by  return val[$scope.corder];}

Demonstration Plunker.