Reputation: 71
I have array of array which needs to be able to be sorted and put in order
my problem is sorting objects by order and array that contains info which both is within the array, my approach was to use
<a ng-repeat="s in stops | orderBy:'+train_routes[0].stop_seq'"
ng-show="s.train_routes[0].route_id.indexOf('5') > -1">
because I have a lot of data and I don't want to organize it as it will become a much larger and crash
I know the problem is [0], but I don't know any other way
I want it to show the object that has the array containing info
This works
ng-show="s.train_routes[0].route_id.indexOf('6') > -1"
this doesn't work
ng-show="s.train_routes[0].route_id.indexOf('5') > -1">
http://plnkr.co/edit/MbjKKtTbs3EgO6a4WCRL?p=preview
EDITED Let's say the user wants to see specific train route, it must show all the stops on that train line, and show the other available trains linked to the requested by the user.
ng-show="train_routes[0].IndexOf('requestedroute')"
will only show if the 0 index matches the requested route.
I will like it to show all the values in every index if the array contains the requested route
Upvotes: 3
Views: 672
Reputation: 6484
You can use Angular filters, so that you do not append useless elements in the DOM.
In the view:
<a ng-repeat="s in stops | filter: avoid5 | orderBy:'+train_routes[0].stop_seq'">
In the controller:
$scope.avoid5 = function(value, index, array){
return value.train_routes[0].route_id.indexOf('5') > -1;
}
Upvotes: 3