如何在 angular js material 设计中动态启用或禁用输入字段

How to enable or disable input fields dynamically in angular js material design

我遇到了 ng-disable 的问题。因为我正在使用 angular material,所以我认为这是行不通的。我希望根据条件动态禁用或启用我的输入框。

注意:- 我有多个输入字段,我想一次性禁用或启用所有输入字段。

我正在这样尝试

<md-input-container class="md-block" flex-gt-sm>
    <label for="Autocomplete">From</label>
    <input required type="text" class = "hideShadow" ng-model="FromLocation"
           uib-typeahead="state for state in states | filter:$viewValue | limitTo:8" 
          class="form-control" ng-disabled="isDisabled">
    <div ng-messages="searchFlight.FromLocation.$error">
    <div ng-message="required">Please enter from location</div>
     </div>
</md-input-container>

我正在尝试像这样动态访问 ng-disabled="isDisabled"

$scope.isDisabled = true;

但这不起作用。我可以知道我哪里错了吗?

我认为问题在于您绑定 属性 isDisabled 的方式。

试试这个:

$scope.model = {
    isDisabled: true
};

然后:

ng-disabled="model.isDisabled"

当我们尝试在指令上绑定原语 属性 时会出现此问题。我们需要绑定一个对象的属性才能正常工作。

您可以使用 ng-disabled 启用或禁用该字段

例如,如果您最初想禁用某个按钮,但在执行某项操作后又想启用该按钮,

<button class="btn btn-default" type="submit" ng-disabled="isDisabled" ng-click="ok()">OK</button>

$scope.isDisabled = true;

$scope.save = function(){
//after completing the operation set the values of variable to false
$scope.isDisabled = false;
}