【问题标题】:How to enable or disable input fields dynamically in angular js material design如何在角度 js 材料设计中动态启用或禁用输入字段
【发布时间】:2017-03-08 05:47:56
【问题描述】:

我遇到了 ng-disable 的问题。当我使用有角材料时,我认为这是行不通的。我希望根据条件动态禁用或启用我的输入框。

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

我正在尝试这样

<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;

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

【问题讨论】:

  • 角度是否正常工作,控制台中没有错误?
  • 控制台没有错误
  • 介意分享你的js代码吗?
  • 我不介意分享,但它很重。
  • 我找到了解决方案。我把我的 JS 放在错误的地方我的坏:(

标签: angularjs angular-material angularjs-ng-disabled


【解决方案1】:

您可以使用 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;
}

【讨论】:

    【解决方案2】:

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

    试试这个:

    $scope.model = {
        isDisabled: true
    };
    

    然后:

    ng-disabled="model.isDisabled"
    

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

    【讨论】:

      猜你喜欢
      • 2019-05-22
      • 1970-01-01
      • 2018-12-26
      • 2015-07-28
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-24
      相关资源
      最近更新 更多