6

I am having an issue with ng-disable. as i am using angular material i think this is not working. I want my input box to be disabled or enabled dynamically based on condition.

Note:- I have multiple input fields i want disable or enable all of the at a single shot.

I am trying like this

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

I am trying to access ng-disabled="isDisabled" dynamically like this

$scope.isDisabled = true;

But this is not working. May i know where i am going wrong?

5
  • Is angular working, no errors in console? Commented Oct 26, 2016 at 2:10
  • no errors in console Commented Oct 26, 2016 at 2:12
  • Mind sharing your js code? Commented Oct 26, 2016 at 2:14
  • i don't mind to share but it is quite heavy. Commented Oct 26, 2016 at 2:21
  • I got a solution. i am keeping my JS in wrong place my bad :( Commented Oct 26, 2016 at 5:13

2 Answers 2

8

I believe the problem is in the way you did bind the property isDisabled.

try this:

$scope.model = {
    isDisabled: true
};

Then:

ng-disabled="model.isDisabled"

This problem occur when we try to bind a primitive property on a directive. We need to bind a attribute of a object to work properly.

Sign up to request clarification or add additional context in comments.

Comments

2

You can enable or disable the field by using ng-disabled

For example, if you want to disable a button initially and after performing something you want to enable the button,

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.