如何预加载 Angular material select 中的值?

How can pre-load the value in Angular material select?

我想预载md中的值-select

我有以下代码

<md-select ng-model="country" ng-model-options="{trackBy: '$value.code'}" >
    <md-optgroup label="Country">
        <md-option ng-value="country" ng-repeat="country in countries">
                    {{country.name}}
        </md-option>
    </md-optgroup>
</md-select>

控制器

 $scope.country = "usa"; //I will receive only the key from the server side 
                         //in the response object

$scope.countries = [{"code":"usa","name":"United States of America"},
  {"code":"ind","name":"India"},
  {"code":"eng","name":"England"},    
  {"code":"aus","name":"Australia"}];

这里我想先加载"United States of America"。

目前无法正常工作。

假设您的服务 returns 键 "usa",它检查下拉数组中是否存在键并将对象分配给 $scope.country

app.controller('myCtrl', function($scope) {
 $scope.service = "usa";
$scope.countries = [{"code":"usa","name":"United States of America"},
  {"code":"ind","name":"India"},
  {"code":"eng","name":"England"},    
  {"code":"aus","name":"Australia"}];

   angular.forEach($scope.countries, function(value) {
        if (value.code === $scope.service ) {
            $scope.country ={code: $scope.service , name: value.name};
            console.log($scope.country);
        }
    });

});

WORKING DEMO