I am trying to use Angulars group-by syntax to create a dropdown for data of the form
[{name:'xyz', subitems:[{}...N]}...N] (see below)
http://plnkr.co/edit/Rthy3Bje7ISYVOSwzIZZ?p=preview
It doesn't seem like group-by supports this structure and so I am left using ng-repeat on optgroup elements. This puts me in the position of having to treat the selected item as a string which I then have to parse back to an object.
Question 1: Can Angular's group-by syntax work on my data structure to yield appropriate optgroups?
If Not Then
Question 2: Is my current implementation using ng-repeater over optgroups the basic flavor I will have to use to solve this problem or am I missing a simpler solution?
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.3.0" src="//code.angularjs.org/1.3.0/angular.js"></script>
</head>
<body ng-controller="myCtrl">
<h3>Can select-group-by expression be used here????</h3>
<select ng-options="obj.name for obj in data" ng-model="selectedObj">
</select>
{{selectedObj}}
<h3>In lieu of repeating optgroups?</h3>
<select ng-model="selectedModel2" ng-change="convert()">
<optgroup ng-repeat="obj in data" label="{{obj.name}}">
<option value="{{bsnObj}}"
ng-repeat="bsnObj in obj.bsnObjs">{{bsnObj.name}}</option>
</optgroup>
</select>
{{selectedModel2}}
<script>
var app=angular.module("app",[]);
app.controller("myCtrl",function($scope){
$scope.convert=function(){
$scope.selectedModel2 = JSON.parse(this.selectedModel2);
};
$scope.data=[
{"name" : "forms", bsnObjs: [{name:"formA"},{name:"formB"}]},
{"name" : "docs", bsnObjs: [{name:"docsA"},{name:"docsB"}]}
]
});
angular.bootstrap(document,["app"]);
</script>
</body>
</html>
ng-optionswithgroup by. Otherwise, that's seems fine.