I need some help. I can't create $scope.headline.category
into an object, it has to stay a string. The groupList
has to be a list of objects. How can I set the initial value of the dropdown to the 2nd item (1 index)? I can set it through the controller but I have a lot of items and it seems like there should be an easier way... maybe using ng-init
? Thank you for any help.
What I tried but doesn't work:
ng-init="headline.category = group.label"
What I tried that does work, but i feel like there's an easier way?
for (var a = 0; a < $scope.headlineList.length; a++) {
for (var b = 0; b < $scope.groupList.length; b++) {
if ($scope.headlineList[a].category == $scope.groupList[b].label) {
$scope.headlineList[a].category = $scope.groupList[b];
}
}
}
Angular
$scope.headline.category = "B";
$scope.groupList = [ {label: "A"}, {label: "B"}, {label: "C"} ];
HTML
<select ng-model="headline.category" ng-options="group.label for group in groupList"></select>