Angularjs 如何在角材质选择中预加载值?
我想在md select中预加载该值 我有以下代码Angularjs 如何在角材质选择中预加载值?,angularjs,angularjs-select2,angularjs-material,Angularjs,Angularjs Select2,Angularjs Material,我想在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"> {{co
<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>
这里我想先加载“美利坚合众国”
这目前不起作用。假设您的服务返回密钥
“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);
}
});
});
我只想发送所选对象的代码。ng value=“country.code”不预加载数据。选择也不起作用。如果我选择任何一个国家,它会选择下拉列表中的最后一个条目。我怎样才能只发送钥匙
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);
}
});
});