Hey so I need to populate my select box with a list of Regions from Json object. There are duplicates in here that I would like to remove and I have set the alphabetical order.
I also need to use track by job.WS_REGION so that the value is set to the region just now I think it is tracking index so assigning a number to the value.
Can track by be used in conjunction with filters?
They work perfect independent of each other either by assigning value or applying filters.
<select ng-model="filterzz" ng-options="job.WS_REGION for job in jobsfull track by job.WS_REGION | orderBy: 'WS_REGION' | unique:'WS_REGION'">
If this is a simple mistake go easy on me its a Friday afternoon :)
In AngularJS when you are using ng-options, you can filter out the options by calling a custom function you have in the controller. Let's say you have following set of employees and when you display all these employees inside HTML select using ng-options, you can see all the employees in a dropdown.
The ng-options Directive in AngularJS is used to build and bind HTML elements with options to a model property. It is used to specify <options> in a <select> list. It is designed specifically to populate the items on a dropdown list. This directive implements an array, in order to fill the dropdown list.
In my opinion the correct way to set a default value is to simply pre-fill your ng-model property with the value selected from your ng-options , angular does the rest. Essentially when you define the $scope property your select will bind to assign it the default value from your data array.
"track by" tells the angular js that how angular js will track the association between DOM and the model (i.e. collection). Internally angular js uses "track by $id(obj)" for this purpose. You can use track by $index if you do not have a unique identifier.
Try parentheses:
ng-options="job.WS_REGION for job in (jobsfull | orderBy: 'WS_REGION' | unique:'WS_REGION') track by job.WS_REGION"
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