角度材料:md-选择不使用"控制器为"句法?

时间:2016-04-24 20:46:29

标签: angularjs angular-material

我所做的就是修改他们的官方异步搜索演示(它适合我的用例)以使用"控制器作为",并因此得到奇怪的行为。 Codepen is here。我错过了什么吗?

这里是上述链接的相关代码位:

JS:

angular.module('MyApp',['ngMaterial', 'ngMessages', 'material.svgAssetsCache'])
.controller('SelectAsyncController', function($timeout, $scope) {
  var vm = this;

  vm.user = null;
  vm.users = null;

  vm.loadUsers = function() {
    return $timeout(function() {
      vm.users =  vm.users  || [
        { id: 1, name: 'Scooby Doo' },
        { id: 2, name: 'Shaggy Rodgers' },
        { id: 3, name: 'Fred Jones' }
      ];
    }, 650);
  };
});

标记:

<div ng-controller="SelectAsyncController as vm" layout="column" ng-app="MyApp">
    <md-select placeholder="Assign to user" 
               ng-model="vm.user" 
               md-on-open="vm.loadUsers()">
      <md-option ng-value="vm.user" 
                 ng-repeat="user in vm.users">{{user.name}}</md-option>
    </md-select>
    <p>Assigned to: {{ vm.user ? vm.user.name : 'No one yet' }}</p>
</div>

1 个答案:

答案 0 :(得分:0)

您应该将ng值更改为“user”。

<md-option ng-value="user" ng-repeat="user in vm.users">{{user.name}}</md-option>

这是工作Codepen