Cant find syntax error


#1

Hi,

I’m trying to make pip in order to sort items in cols, according to this tutorial:
http://www.fueltravel.com/blog/migrating-from-angular-1-to-2-part-1-pipes/

What ist wrong with these lines?
I get following error:
Expression expected at the ?

return input.sort(function(a:any,b:any){
return !desc ?
? OrderBy._orderByComparator(a[property], b[property])
: -OrderBy._orderByComparator(a[property], b[property]);
});

Thanks a lot!


#2

Looks like you’ve added a double question mark in your ternary operator:

!desc ? <- first one
? <- second one OrderBy._orderByComparator(a[property], b[property])
: -OrderBy._orderByComparator(a[property], b[property]);```

#3

Oh, sorry. All right! Thank you.


#4

Please, help me once again:
I did the following

  <ion-item-sliding *ngFor="let item of items  | orderBy : 'name'">
    <ion-item >

I get “Cannot read property ‘toLowerCase’ of undefined”

Can you tell me why? Thanks a lot!!!


#5

A pipe is the wrong choice here. Please read this (all the way to the end) for more details and what you should be doing instead.


#6

@rapropos and @SigmundFroyd and all others
Ok, thank you. I think, I have understood the use of pipes.
But I still have my problem with my original plan: I have a table, respectively a grid-construction, with three columns, with header named colA, colB, colC. I “just” want to order my rows asc/desc by klicking on the single headers.
I hope I do not sound rude, but could someone give me a sample code for that? How big would be the effort. What would that cost me? I’m really desperate!
Thank you very much!


#7

I found this tutorial: https://www.djamware.com/post/5a37ceaf80aca7059c142970/ionic-3-and-angular-5-search-and-sort-list-of-data

It works fine!