cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div ng-app="App" id="page-wrapper" ng-controller="contentController">
	<h1>AngularJS Edit-in-Place with contenteditable</h1>

	<section>
		<h2>The contenteditable directive</h2>

		<div contenteditable="true" ng-model="text01">
		</div>
	</section>

	<section>
		<h2>Toggle Editing</h2>
		
		<button id="editorBtn" type="button" ng-click="toggleEditMode()">{{editmode ? 'Disable Editing' : 'Enable Editing'}}</button>
		<div id="editor" ng-model="text02" ng-attr-contenteditable="{{ editmode }}">
		</div>
	</section>

</div>
            
          
!
            
              html {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 100%;
  background: #333;
  color: #555;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

#page-wrapper {
  width: 720px;
  background: #FFF;
  padding: 1em;
  margin: 1em auto;
  min-height: 300px;
  border-top: 5px solid #69c773;
  box-shadow: 0 2px 10px rgba(0,0,0,0.8);
}

h1 {
  margin-top: 0;
  line-height: 1.3em;
  color: #1E1E1E;
}

h2 {
  font-weight: normal;
  font-size: 1.4em;
  margin: 1.5em 0 0.5em;
  color: #1E1E1E;
}

button {
  display: inline-block;
  border-radius: 3px;
  border: none;
  font-size: 0.9rem;
  padding: 0.4rem 0.8em;
  background: #69c773;
  border-bottom: 1px solid #498b50;
  color: white;
  -webkit-font-smoothing: antialiased;
  font-weight: bold;
  margin: 0 0 1em;
  text-align: center;
}

button:hover, button:focus {
  opacity: 0.75;
  cursor: pointer;
}

button:active {
  opacity: 1;
  box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.1) inset;
}

div,
p {
  line-height: 1.6em;
}

section > div {
  padding: 1em;
  border-radius: 3px;
  outline: none;
  border: 2px solid transparent;
}

section > div[contenteditable='true']:hover{
  background: #E6E6E6;
}

section > div:focus, section > div:focus:hover  {
  background: #FFF;
  border-color: #69c773;
  box-shadow: 0 1px 5px rgba(0,0,0,0.15) inset;
}

            
          
!
            
              var app = angular.module("App", []);

app.controller('contentController', ['$scope', function($scope) {
  $scope.text01 = 'Click here to edit the text.';
  $scope.text02 = 'You will need to click the button to enable content editing before you can change this text.';
  $scope.editmode = false;
  $scope.toggleEditMode = function(){
    $scope.editmode = $scope.editmode === false ? true: false;
  }
}]);

app.directive("contenteditable", function() {
  return {
    require: "ngModel",
    link: function(scope, element, attrs, ngModel) {

      function read() {
        ngModel.$setViewValue(element.html());
      }

      ngModel.$render = function() {
        element.html(ngModel.$viewValue || "");
      };

      element.bind("blur keyup change", function() {
        scope.$apply(read);
      });
    }
  };
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console