Frage

I'm trying to enable and disable the button using some condition

I am able to disable the button using $scope.isDisabled = true; , but can't enable the button

Here is my code

HTML file

<input type="submit" value="Continue" ng-model="isDisabled" ng-disabled="isDisabled">

Controller JS file

$scope.isDisabled = true; // here the button disabled (for me)

if (count >= 3) {       // it's always true          
      $scope.isDisabled = false;   // try to enable the button here
}
War es hilfreich?

Lösung

  1. Do not use $scope.apply. That is not what it is meant for.
  2. The button does not need to be bound to a model, try removing the ng-model from the button.
  3. Also, if it is an input type of "submit" and you are not inside an ng-form, that might cause a postback and you might lose your state.

Here is a plunk that shows it working - i made some assumptions to get the plunk going. added an extra button that triggered the count increments.

http://plnkr.co/edit/QGYMqGHCKUoDGaY9WYhj?p=preview

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top