I have a dynamic data model coming in via a websocket, which looks like this:
var results = [
[
{name:'A'},
{price: 0.00}
],
[
{name:'C'},
{price: 0.00}
],
]
I'm using my ng-repeat as follows:
ng-repeat="result in results"
Whenever I need to access one of the arrays within the result array I do:
result[0].name
The issue I'm having is that the orderBy filter on ngRepeat doesn't seem to allow me to do this:
ng-repeat="result in results | orderBy: result[0].name
Perhaps it's a basic misunderstanding of how Angular works, but I fail to understand why this wouldn't work. Is it incorrect syntax, or is it due to my data model being dynamic? Should I be setting up a $scope.$apply somewhere?
I've tried with quotes, and I've tried setting up a predicate in the function that parses the data initially, setting predicate to each instance of the result.name as it comes through, but this also doesn't work.
Any help is very much appreciated.
This question is really interesting. Since orderBy will be using the current object, you have to assign the order string relatively.
This will do the trick:
ng-repeat="result in results | orderBy: 'this[0].name'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With