nuway
nuway

Reputation: 2394

Angular - orderBy string as number

Im using youtube json api and it returns the viewcount as a string, but i need to sort it as an number. How could i do this without going thru the whole model and converting strings to ints?

json snippet

yt$hd: Object
yt$statistics: Object
favoriteCount: "0"
viewCount: "1443"
__proto__: Object

and im invoiking sorting like

orderBy:'yt$statistics.viewCount'

Upvotes: 0

Views: 237

Answers (1)

idbehold
idbehold

Reputation: 17168

Not that firmilar with Angular, but I'd assume that orderBy parameter can take a function in place of a string like Lo-Dash does with its `sortBy() function. In which case you'd probably want something like this:

orderBy: function(obj){
  return ~~obj.yt$statistics.viewCount
}

Upvotes: 1

Related Questions