123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              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}}

            
          
!
            
              

/* -=-=-=-=- -=[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; }

            
          
!
            
              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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console