2

In a json object i filtered duplicate product and get array for creating dropdone for search.

$scope.value =[{"Product":"Table","Country":"United States","id":"17619"},{"Product":"Chair","Country":"Pakistan","id":"17618"},{"Product":"Keyboard","Country":"Pakistan","id":"17617"},{"Product":"Chair","Country":"Pakistan","id":"17615"}]

I filtered duplicate products and get array by this method

$scope.getProduct = function(){return ($scope.values || []).map(function(w){return w.Product;}).filter(function(w,idx,arr){return arr.indexOf(w)===idx;});};

it return Table, Char, Keyboard as array. which i used in dorpdonw by getProduct() function in this way

<select ng-model="product"><option ng-repeat="p in getProduct()" ng-model="filter[p]">{{p}}</option></select>

But i want output in sorted form like Char,Keyboard,Table. How can i sort array return by getProduct()

1
  • what is ng-model="filter[p]" in option? you already have a model tagged to your select with ng-model="product". Commented Feb 22, 2019 at 7:35

1 Answer 1

1

You can use orderBy filter of angularjs to achieve that.

<select ng-model="product"><option ng-repeat="p in getProduct() | orderBy" ng-model="filter[p]">{{p}}</option></select>

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

@Deepak3301086 I'm glad I could help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.