I have a md-select
set up as follows:
In my case adding ng-model-options="{trackBy: '$value.id'}"
as described in the docs did not work, as no initial value was set.
By explicitly setting the model to the wished default value in the controller properly set the value as desired. This approach might be easier if you do not know up front the index of the element you want to display as pre-selected (using ng-selected
). Of course you can evaluate it in the controller, but to me it seems more immediate to set the target element directly to the model.
View:
{{item.value}}
Controller:
function initialize() {
vm.globalFilterValues = globalFilterValues;
vm.selectedGlobalFilter = TransferGlobalFilter.Worldwide;
}
Where globalFilterValues are in the form:
[
{key:"All", value:"All values" },
{key:"Manager", value:"Manager"},
{key:"HR", value:"Human resources"},
]