vendredi 27 mars 2020

How to disable button without changing of ng-if condition for input type checkbox using angularjs?

I have one interesting situation, I have the below code.

Js:

<script>
  var app = angular.module('MyApp', []);    
    app.controller('MyCtrl', function($scope) {
      $scope.a=10;
    });
</script>

html:

<body ng-app="MyApp">
  <div ng-controller="MyCtrl">
    Click Me: <input type="checkbox" ng-model="checked" ng-if="a===10"/> <br />
    <button ng-disabled="checked">Test</button>
  </div>
</body>

If I run the above code, Test button is not disabling. I am not sure why ?

But, as per my requirement, that ng-if condition should be there in <input /> tag only and I cannot write or combine <input /> and <button> tags in one <div> as well.

So, please help me, to have any other way to get my Test button should be in disabled mode on clicking of input type checkbox without changing of above sample code.

Codepen.




Aucun commentaire:

Enregistrer un commentaire