如何在下拉列表中使用ng-class

时间:2014-07-30 12:49:26

标签: javascript html angularjs

我不熟悉AngularJS中的ng-class,我需要知道如何在选择选项时禁用AngularJS中的选择列表,并在没有选择选项时启用它。如果对象为空,则启用选择列表和如果和对象不为空则禁用选择列表。这就是我尝试过但它没有用的

HTML

<select class="categories" ng-class="{'disabled':Model.CurrentDowntime.CategoryId !== 0}"  ng-model="Model.CurrentDowntime.CategoryId" ng-options="downtimeCategory.CategoryId as downtimeCategory.CategoryName for downtimeCategory in Model.DowntimeCategories">
</select>

JS

angular.module('myApp', [])

 .controller('DowntimeController', function ($scope, $http) {
     $scope.Model = new Model($http);
     $scope.Model.CurrentDowntime = {};   
});

1 个答案:

答案 0 :(得分:0)

disabled是一个属性,而不是一个类。使用ng-disabled

<select class="categories"
        ng-disabled="Model.CurrentDowntime.CategoryId !== undefined"
        ng-model="Model.CurrentDowntime.CategoryId"
        ng-options="downtimeCategory.CategoryId as downtimeCategory.CategoryName for downtimeCategory in Model.DowntimeCategories">
</select>