How might I implement conditional grouping in a Select element using angular?

廉价感情. 提交于 2019-12-06 16:49:56
Piotr Sobczyk

Just generate your ng-options expression in JavaScript (controller). Depending of some conditional logic assign different expression.

For example:

<select ng-model="tcCtrl.SelectedItem" 
        ng-options="{{ selectOptions }}"></select>

And your controller might look like:

if(groupCondition){
  $scope.selectOptions = "item.Id + ' - ' + item.Description 
                group by item.GroupDescription 
                for workType in ctrl.Context.ItemList";
} else {
  $scope.selectOptions = "item.Id + ' - ' + item.Description for workType in ctrl.Context.ItemList";
}

Also, shouldn't expression be "... for item in ctrl.Context.ItemList" instead of workType in your case?

See also this answer .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!