我需要禁用md-select,但我无法在Angular文档中找到它。
这是我的代码:
<md-select ng-model="idSelectedMonth" placeholder="Month">
<md-option ng-repeat="month in months" ng-value="month.number">
{{month.number}}
</md-option>
</md-select>
答案 0 :(得分:8)
您可以在md-select标记上使用ng-disabled="true"
,如下所示
(function () {
'use strict';
var app = angular.module("App",["ngMaterial"]);
app.controller("ctrl", [function () {
/* jshint validthis: true */
var vm = this;
vm.title = "Hello World !";
vm.items = [
{id:-1, text:"No Selection"},
{id:1, text:"Item 1"},
{id:2, text:"Item 2"},
{id:3, text:"Item 3"},
{id:4, text:"Item 4"},
];
return vm;
}]);
})();
<!DOCTYPE html>
<html ng-app="App">
<head>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="https://gitcdn.xyz/repo/angular/bower-material/master/angular-material.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-animate.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-aria.js"></script>
<script src="https://gitcdn.xyz/repo/angular/bower-material/master/angular-material.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller="ctrl as vm">
<h1>{{vm.title}}</h1>
<md-input-container>
<label>Please choose</label>
<md-select flex ng-model="vm.selected" ng-disabled="true">
<md-option ng-value="item" ng-repeat="item in vm.items">
<span ng-show="item.id>0"> {{item.text}}</span>
<span ng-show="item.id<0" class="highlight"> {{item.text}}</span>
</md-option>
</md-select>
</md-input-container>
</div>
</body>
</html>
您可以使用“false”
来检查ng-disable =“true”答案 1 :(得分:4)
ng-disabled
工作得很好。这是展示它的JSFiddle。
<md-select ng-model="idSelectedMonth" placeholder="Month">
<md-option ng-repeat="month in months" ng-value="month.number" ng-disabled="true">
{{month.number}}
</md-option>
</md-select>
答案 2 :(得分:0)
您可以有条件地禁用md-select和md-option
<md-input-container class="md_dropdown">
<label>--Select--</label>
<md-select ng-disabled="<condition>" ng-model="vm.selectedValue">
<div ng-repeat="value in vm.values">
<md-option
ng-disabled="vm.checkDisabled(value)"
ng-value="value">{{value}}</md-option>
</div>
</md-select>
</md-input-container>