选定的值不适用于md选择AngularJS

时间:2018-01-09 09:43:43

标签: angularjs angularjs-material

我使用AngularJS材质选择选项,我想将当前选定的值设置为选项。我尝试了不同的方法而不是工作。这是我试过的。用户单击时,应触发更改。

  <div flex>
    <md-select ng-model="$callcenterController.selectedLanguage"  ng-change="$callcenterController.languageChange($callcenterHomeController.selectedLanguage.name)" placeholder="{{$callcenterController.selectLanguageLabel}}" ng-model-options="{trackBy: 'languages.name' }"
    >
        <md-option ng-value="languages" ng-repeat="languages in $callcenterHomeController.languageList"> {{ languages.name }}</md-option>
    </md-select>

1 个答案:

答案 0 :(得分:1)

试试这个

angular.module('MyApp', ['ngMaterial'])
.controller('MyCtrl', function ($scope) {
  $scope.languageList = [
    {
      id: 1,
      name: "option 1"
    },
    {
      id: 2,
      name: "option 2"
    },
    {
      id: 3,
      name: "option 3"
    }

  ];
});
<html ng-app="MyApp">
  <head>
    <link href="https://rawgit.com/angular/bower-material/master/angular-material.css" rel="stylesheet"/>
  </head>
  <body>
		<div ng-controller="MyCtrl" layout layout-align="center center">
			<md-select ng-model="myModel" placeholder="Pick">
				<md-option ng-value="{{ languages.id }}" ng-repeat="languages in languageList"> {{ languages.name }}</md-option>
			</md-select>
		</div>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.8/angular.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.8/angular-animate.js"></script>
		<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.8/angular-aria.js"></script>
		<script src="https://rawgit.com/angular/bower-material/master/angular-material.js"></script>
  </body>
</html>