0

I am trying to use angular orderBy to order multiple fields, but i get syntax error as:

Syntax error, unrecognized expression: div[ng-repeat='r in vm.GetRequests() | filter: vm.SearchText | orderBy:['LastName','FirstName']']

It seems there appears additional sign ']', but i do not have it in html

The html looks like:

<div ng-repeat="r in vm.GetRequests() | filter: vm.SearchText |orderBy:'RequestedOn'| orderBy:['LastName','FirstName']">
{{r.LastName}} : {{r.FirstName}}
</div>

the function GetRequests() returns a array of object as following:

[{FirstName:"Test1", LastName:"First"},{FirstName:"Test2",LastName:"Second"},{FirstName:"Test3",LastName:"Third"}]

Can anyone help me for the problem?

Changing HTM - remove orderBy: 'RequestedOn'

<div ng-repeat="r in vm.GetRequests() | filter: vm.SearchText | orderBy:['LastName','FirstName']">
{{r.LastName}} : {{r.FirstName}}
</div>

but i still get syntax error:

Uncaught Error: Syntax error, unrecognized expression: div[ng-repeat='r in vm.GetRequests() | filter: vm.SearchText | orderBy:['LastName','FirstName']'] 

UPDATE

The syntax seems comes from a browserlink, because the order works goed when i get the error. And recommend to put all order property in a array

Thanks a lot for the inputs all of you, especially thanks for RishiPrakash :)

9
  • try <div ng-repeat="r in vm.GetRequests() | filter: vm.SearchText | orderBy:['RequestedOn','LastName','FirstName']"> Commented Dec 29, 2014 at 11:12
  • see, in the error it ,orderBy : RequestedOn is not present, error must be related to it. Commented Dec 29, 2014 at 12:05
  • @ Rishi Prakash - I remove the first orderBy: 'RequestedOn', but i still get this error : Uncaught Error: Syntax error, unrecognized expression: div[ng-repeat='r in vm.GetRequests() | filter: vm.SearchText | orderBy:['LastName','FirstName']'] Commented Dec 29, 2014 at 12:11
  • that last ] is actually end seniter of div[ng-repeat in error , atleast this riddle is solved Commented Dec 29, 2014 at 12:16
  • @ Rishi Prakash - i see now , the last ']' is the end of error tag, now i do not understand why i still get syntax error. I have already updated the HTML Commented Dec 29, 2014 at 12:20

2 Answers 2

0

I think that filter only works on arrays and doesn't evaluate functions. I would assign the request to a scope variable in the controller:

js:

$scope.requests = vm.GetRequests();


html:

<div ng-repeat="r in requests | filter: vm.SearchText | orderBy:['RequestedOn','LastName','FirstName']"> {{r.FirstName }}, {{r.LastName}} </div>



note: I don't think there's a problem with the way you sort your array, although I prefer combining them in one orderBy expression as Rishi Prakash suggested.

Sign up to request clarification or add additional context in comments.

4 Comments

I do not have any problem if i have just one string ,like "orderBy: 'RequestedOn'", it is working for ordering based on RequestedOn property, and it is also working if i use "orderBy: 'RequstedOn' | orderBy:'FirstName'". But it is not working if use array, like order:['RequestedOn','FirstName','LastName']--- as i said 'RequestedOn' is not the reason of syntax error
I said that the problem is with vm.GetRequests() not RequestedOn. orderBy expression is fine.
i use typescript and the generated javascript for function GetRequests() looks like: ModelName.prototype.GetRequests = function() {...}, i think this is the same as what you mean for $scope.requests = vm.GetRequests(), is it?
I meant that ng-repeat won't work right in the way you're doing, use a scope variable if you don't really need a function. for more details see this post it will help you: stackoverflow.com/questions/12336897/…
0

try <div ng-repeat="r in vm.GetRequests() | filter: vm.SearchText() | orderBy:['RequestedOn','LastName','FirstName']">

filter:vm.SearhText must be a function so () in end of it.

6 Comments

"RequestedOn" is also a property of the object, and it is a moment object. First i thought maybe the moment object can not be sorted, that is why i do not put it in the output array. But it is not the reason,i still get the same error
tell me the value of moment object?
@ Rishi Prakash - and another reason i put "RequestedOn" in a seperate orderBy is the array does not correct order for properties "LastName" and "FirstName" if i put "RequestedOn" also in the order array
these two object has following moment:1. d: Mon Oct 27 2014 16:27:30 GMT+0100 (Romance Standard Time)_f: "YYYY-MM-DDTHH:mm:ss"_i: "2014-10-27T16:27:30"_isAMomentObject: true_isUTC: false_locale: Locale_pf: Object__proto_: Moment and 2. d: Mon Oct 27 2014 10:00:00 GMT+0100 (Romance Standard Time)_f: "YYYY-MM-DDTHH:mm:ss"_i: "2014-10-27T10:00:00"_isAMomentObject: true_isUTC: false_locale: Locale_pf: Object__proto_: Moment
Ok, I have create the jsfiddle jsfiddle.net/U3pVM/11581 , can you create the case there?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.