Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="myApp">
  <div ng-controller="MyController">
      <input type="text" ng-model="newBackground" placeholder="Image URL for new background..." />
      <button background-changer="{{newBackground}}" placeholder="Change background...">Change background</button>
  </div>
</body>
</html>
 
angular.module('myApp', []);
angular.module('myApp')
  .controller('MyController',MyController);
MyController.$inject = ['$scope'];
function MyController($scope) {
  $scope.newBackground = '';
  // all your other code
}
angular.module('myApp')
  .directive('backgroundChanger',backgroundChanger);
function backgroundChanger() {
  var d = {
    link: link
  };
  
  function link(scope, el, attrs) {
    el.on('click',function() {
      var bg = attrs.backgroundChanger;
      
      $('body').css({
        'background-image': 'url('+bg+')'
      });
    });
  }
  
  return d;  
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers