title: Changing body background color with angularjs
body: <p>I want to be able to change the background color of <code>&lt;body&gt;</code> depending on what the current path is.</p>
  
  <p>I tried doing it by checking $location.path() whenever the path was changed and then using the <code>ng-style</code> directive to change the background color but this seems like a hack (and didn't work).</p>
  
  <p>What would be a more decoupled way to achieve this?</p>
  
  <p>Here's the code I wrote if anyone wants to see it.</p>
  
  <pre><code>app.controller('backgroundCtrl', ['$rootScope', '$scope', '$route', '$location', function($rootScope, $scope, $route, $location){
    $rootScope.$on('$routeChangeStart', function(){
  
      if ($location.path() == '/'){
        $scope.backgroundStyle = {background: '#ffffff'};
      } else {
        $scope.backgroundStyle = {background: '#000000'};
      }
  
    });
  }]);
  </code></pre>