I am in need of assistance. I am struggling to convert $scope.headline.category
into an object; it must remain a string. The groupList
needs to be a list of objects. Is there a way to set the initial value of the dropdown to the 2nd item (1 index) without having to do it through the controller? Perhaps utilizing ng-init
? Thank you for any guidance.
My unsuccessful attempt:
ng-init="headline.category = group.label"
The solution that works, but I feel like there should be a simpler approach:
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>