Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html> 
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  <link rel="stylesheet" href="https://codemirror.net/lib/codemirror.css">
  <script src="https://code.jquery.com/jquery-3.1.0.js"></script> 
  <script src="https://codemirror.net/lib/codemirror.js"></script>
  <script src="https://codemirror.net/mode/css/css.js"></script>
</head>  
<body>
  <div ng-app="myApp" ng-controller="myCtrl">
    HTML:<br>
    <textarea rows=10 cols=40 ng-model="area1">html body area</textarea>
    <br>CSS:<br>
    <textarea class="code" code-mirror>body {color: green}</textarea>
  </div>
  Output:
  <section id="output">
    <iframe></iframe>
  </section>
</body>
</html>
 
var app = angular.module('myApp', []);
    
app.controller('myCtrl', function($scope) {
    $scope.area1 = "<body>default</body>";  
    $scope.$watch('area1', function (json) {
      render();
    }, true);
  
    $scope.css="body {color: red}";
  
    function render () {
      var source = "<html><head><style>" + $scope.css + "</style></head>" + 
                   $scope.area1 +"</html>";
     
      var iframe = document.querySelector('#output iframe'),
          iframe_doc = iframe.contentDocument;
     
      iframe_doc.open();
      iframe_doc.write(source);
      iframe_doc.close();
    }
 });
app.directive('codeMirror', function () {
  return {
    link: function (scope, elm, attrs) {
      console.log("begin");
      var cm_opt = { mode: 'css', gutter: true, lineNumbers: true };
      console.log("here");
      var editor = CodeMirror.fromTextArea(elm, cm_opt);
      console.log("end");
    }  
  }
});
Output

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

Dismiss x
public
Bin info
chengtiepro
0viewers