How to remove the style when the checkbox is unchecked in Angularjs?

Asked

Viewed 138 times

1

I need to change the background color of the page when I check box and return the original color when I uncheck, I only got the first step and I can’t get back the original color, someone help.

<body ng-app='turma' ng-style='fundo'>
<label><input type="checkbox" ng-checked='fundo={"background-color":"#333", color:"white"}'>Fundo escuro</label>

1 answer

1

Try this:

var app = angular.module("testApp", []);
app.controller('testCtrl', function($scope){
   $scope.inventory = {productName:false};
})
.checked{
    background-color:grey;
  }

.unchecked{
   background-color:white;
  }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="testApp" ng-controller="testCtrl">
  
  <div ng-class = "{'checked': inventory.productName, 'unchecked' : !inventory.productName}">
   <input type="checkbox"  class="checkbox" ng-model="inventory.productName"  />Fundo escuro
  </div>

</div>

  • the code didn’t work

  • in the stack compiler is working, click on the "Run"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.