How to remove the style when the checkbox is cleared in AngularJS?

1

I need to change the background color of the page when I mark the checkbox and go back to the original color when I uncheck it, I only got the 1st step and can not return 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>
    
asked by anonymous 11.11.2017 / 15:09

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><divng-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>
    
11.11.2017 / 15:29