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

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.

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
  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") {{ $index + 1 }}
    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$") {{ $index + 1 }}
  
  // -=-=-=-=- -=[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 = [{}, {}, {}];
  var items$ = new Rx.BehaviorSubject(items);
  
  // Variables - Public
  self.items = items;
  self.items$ = items$;
  
  // Functions - Public
  self.addItem = addItem;
  self.getWatcherCount = getWatcherCount;
  
  // Function - Definitions
  function addItem() {
    items.push({});
    items$.next(items);
  }
  
  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

Console