Angularjs选择事件处理程序

时间:2016-09-20 18:25:18

标签: javascript angularjs select event-handling angular-material

我一直在寻找一个事件处理程序,它可以帮助我根据我可以在此事件处理程序上插入的逻辑来阻止呈现select元素的下拉列表。有没有办法在Angularjs中为select或md-select执行此操作?

1 个答案:

答案 0 :(得分:0)

禁用md-select是否是您正在寻找的东西? - CodePen

标记

<div ng-controller="AppCtrl as vm" ng-cloak="" ng-app="MyApp" layout="column" layout-align="start start">
  <md-input-container id="myInputContainer">
    <label>Choose</label>
    <md-select ng-model='choice' ng-disabled="vm.disabled">
      <md-option ng-repeat='option in vm.options' value='{{option.value}}'>{{option.label}}</md-option>
    </md-select>
  </md-input-container>
  <md-button class="md-raised md-primary" ng-click="vm.toggle()">Toggle</md-button>
</div>

JS

angular.module('MyApp',['ngMaterial', 'ngMessages', 'material.svgAssetsCache', 'ngDialog'])

.controller('AppCtrl', function() {
  this.disabled = false;

  this.options = [
    {value: 1, label: "Option 1"},
    {value: 2, label: "Option 2"},
    {value: 3, label: "Option 3"}
  ]

  this.toggle = function () {
    this.disabled = !this.disabled;
  }
});