Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                body(ng-app="myApp" ng-controller="AppCtrl as app")
  b Description:
  p
    | A very basic POC of decorating `$watchCollection()` to enable support
    | for observables. Instead of having to check for changes on every `$digest`,
    | it subscribes to the observable.
    br
    sub
      | (Observable expressions are denoted by a trailing `$`.)
  hr
  
  label
    | Use observable: 
    input(type="checkbox" ng-model="useObservable")
  |  | 
  button(ng-click="app.addItem()") Add item
  button(ng-click="app.editItem()") Edit Random item
  hr
  
  div(ng-switch="useObservable")
    div(ng-switch-default)
      b
        | Regular `ngRepeat` expression
        | (watchers: {{ ($$watchers.length || 0) - 1 }})
        //- One watcher is from the `{{ ... }}`, thus -1.        
      div(ng-repeat="item in app.items") {{ item.name }}
    div(ng-switch-when="true")
      b
        | Observable `ngRepeat` expression
        | (watchers: {{ ($$watchers.length || 0) - 1 }})
        //- One watcher is from the `{{ ... }}`, thus -1.        
      div(ng-repeat="item in app.items$") {{ item.name }}
  
  // -=-=-=-=- -=[IGNORE BELOW THIS LINE]=- -=-=-=-=-
  // Page Footer
  small.footer(ng-non-bindable)
    div(app="footerApp" ng-controller="FooterCtrl as footer" ng-cloak)
      span.left
        b Angular v{{footer.version.full}}
        |  ({{footer.version.codeName}})
      span.right
        != '&copy; '
        a(ng-href="{{footer.author.url}}" target="_blank")
          | {{footer.author.name}}

              
            
!

CSS

              
                

/* -=-=-=-=- -=[IGNORE BELOW THIS LINE]=- -=-=-=-=- */
/* Page Footer */
body { padding-bottom: 2em; }
.footer { background-color: White; border-top: 1px solid rgba(100, 100, 100, 0.33); bottom: 0; display: block; font-size: 0.75em; height: 1.5em; left: 0; margin: 0 5px; overflow: auto; padding: 5px; position: fixed; right: 0; }
.footer > div { display: flex; flex-direction: row; }
.footer .left { flex-grow: 2; text-align: left; }
.footer .right { flex-grow: 1; text-align: right; }
[ng-cloak] { display: none !important; }

              
            
!

JS

              
                console.clear();
(function () {'use strict';

angular.
  module('myApp', []).
  controller('AppCtrl', AppCtrl).
  decorator('$rootScope', decorateRootScope).
  directive('test', testDirective);

// Functions - Definitions
function AppCtrl($rootScope) {
  // Variables - Private
  var self = this;
  var items = [{ name: 'John' }, { name: 'Gkalpak' }, { name: 'Igor' }];
  var items$ = new Rx.BehaviorSubject(items);
  
  // Variables - Public
  self.items = items;
  self.items$ = items$;
  
  // Functions - Public
  self.addItem = addItem;
  self.editItem = editItem;
  self.getWatcherCount = getWatcherCount;
  
  // Function - Definitions
  function addItem() {
    items.push({ name: 'Test' });
    items$.next(items);
  }
  
  function editItem() {
    var item = items[Math.floor(Math.random()*items.length)];
    item.name += '2';
  }
  
  function getWatcherCount() {
    var watcherCount = 0;
    var pendingChildHeads = [$rootScope];

    while (pendingChildHeads.length) {
      var currentScope = pendingChildHeads.shift();
      while (currentScope) {
        watcherCount += (currentScope.$$watchers || []).length;
        pendingChildHeads.push(currentScope.$$childHead);
        currentScope = currentScope.$$nextSibling;
      }
    }

    return watcherCount;
  }
}

function decorateRootScope($delegate) {
  var scopeProto = Object.getPrototypeOf($delegate);
  var oldWatchCollection = scopeProto.$watchCollection;
  scopeProto.$watchCollection = newWatchCollection;
  
  return $delegate;
  
  // Helpers
  function newWatchCollection(expr, listener) {
    var scope = this;
    
    if (!/\$$/.test(expr)) {
      return oldWatchCollection.apply(scope, arguments);
    }
    
    var observable = scope.$eval(expr);
    var subscription = observable.subscribe(function(newValue) {
      scope.$evalAsync(function() {
        listener(newValue);
      });
    });
    
    return subscription.unsubscribe.bind(subscription);
  }
}

}());

/* -=-=-=-=- -=[IGNORE BELOW THIS LINE]=- -=-=-=-=- */
/* Page Footer */
(function () {'use strict';
var app = 'footerApp';
angular.module(app, []).controller('FooterCtrl', FooterCtrl);
angular.bootstrap(document.querySelector('[app="' + app + '"]'), [app]);
function FooterCtrl($window) {
  this.version = $window.angular.version;
  this.author = {name: 'GKalpak', url: '//github.com/gkalpak/'};
}
}());

              
            
!
999px
Why did the programmer quit her job? She didn't get arrays.

Console