I'm trying to define a function that can be used to set the default value on a select. The select is populated correctly, but the value passed into the function is undefined. How do I accomplish this?
This is my HTML.
<div id="Option" class="form-group" ng-show="Options.length > 0">
<div class="col-sm-1 col-md-1 col-lg-2" />
<label class="control-label col-sm-3 col-md-3 col-lg-2">Options</label>
<div class="col-sm-2 col-md-2 col-lg-2" >
<select name="OptionSelect" id="OptionSelect" class="form-control"
ng-model="OptionSelectedId"
ng-init="OptionSelectedId = getDefaultOption(Options)"
ng-options="Option.objectKey as Option.label for Option in Options" required >
</select>
</div>
</div>
This is the function on the controller scope
$scope.getDefaultOption=function(arr){
return arr=$.grep(arr, function (dropdownObj) {
return dropdownObj.default === true;
})[0];
}