How can I use ng-select group for boolean with order and label?

I have some data:

0: {id: 1, name: "hhh", description: "hhh", isPopular: false,…}
1: {id: 2, name: "bbb", description: "bbb", isPopular: true,…}
2: {id: 3, name: "ccc", description: "ccc", isPopular: false,…}
3: {id: 4, name: "ddd", description: "ddd", isPopular: true,…}
4: {id: 5, name: "aaa", description: "aaa", isPopular: false,…}
5: {id: 6, name: "ggg", description: "ggg", isPopular: false,…}

      

I would like to appear in ng-select as:

Popular
 BBB
 sss
 Rest
aaa
sss
yyy
HHH

So I used

<select ng-selected="true"
    ng-options="category.name group by category.isPopular for category in ctrl.categories |
        orderBy: ['-isPopular','name']"
    ng-model="myModel.category">
</select>

      

However, this returns:

aaa
ccc
GGG
HHH
True The
 BBB
 ccc

How can I mark the groups and arrange the group?

+3


source to share


2 answers


You need to pass in the name of the group group by

. For example:



<select ng-selected="true"
    ng-options="category.name group by category.isPopular ? 'Popular' : 'The rest' for category in ctrl.categories |
        orderBy: ['-isPopular','name']"
    ng-model="myModel.category">
</select>

      

+3


source


I'm sure if you want to group you should use this:

<select ng-selected="true"
    ng-options="category.name for category in ctrl.categories |
        groupBy: 'category.isPopular' |
        orderBy: ['-isPopular','name']"
    ng-model="myModel.category">
</select>

      



groupBy

is in Angular-filter , so you need to get the syntax right.

+2


source







All Articles