vendredi 5 juin 2020

How to set checkbox should be selected based on conditions using angualrjs?

I have the following code.

html:

<body ng-controller="MainCtrl">
   <div ng-if="isOwner">
      <input type="checkbox" ng-model="checkboxClicked"  
         />
   </div>
        <span ng-show="checkboxClicked">Non Editable</span> 
        <span ng-hide="checkboxClicked">Editable</span>  
  </body>

js:

app.controller('MainCtrl', function($scope) {
  $scope.isOwner="true";
  $scope.checkboxClicked="true";
});
  1. If Owner and checkboxClicked values are true, then checkbox should be always selected by default on execution i.e with Non-Editable. like:

enter image description here

  1. It should execute the same above output by default even though if we refresh the browser also (here also if Owner and checkboxClicked values are true).

  2. As a Owner, we can uncheck this checkbox also, so then output should be with the Editable checkbox i.e, like: Editable.

enter image description here

Please help me in this context to get my desired outputs as per above screenshots and conditions, I have tried with that code, but it is giving with empty checkbox with Non Editable text, as I believe I am failing to write the conditions.

Created Plnkr.




Aucun commentaire:

Enregistrer un commentaire