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="AngularApplication">
  <div class="Container--tall" ng-controller="MainAppController">
    <div class="fun">
      <h4>Random Header for some content on a page</h4>

      <button class="Button button right" ng-click="hide($event)">Hide</button> 
      <button class="Button button left" ng-click="show($event)">Show</button> 
    </div>
  </div>
</body>
              
            
!

CSS

              
                .Container--tall {
  height: 400px;
  background-color: lightgrey;
}

.button {
  vertical-align: bottom;
  float: right;
  &.left {
    float: left;
  }
}

h4 {
  margin-top: 0;
  padding-top: 0;
  vertical-align: bottom;
}

.fun {
  width: 500px;
  display: inline-block;
  margin: 200px auto;
  top: 0; bottom: 0; left: 0; right: 0;
}
              
            
!

JS

              
                let app = angular.module('AngularApplication', ['ngAnimate', 'mooAngular.snackbar']);

app
 /* .service('$mdCompiler', mdCompilerService)
 .factory('$mooSnackbar', ['$document', '$rootScope', '$q', '$compile', '$timeout', '$rootElement', '$animate', '$mdCompiler', MooSnackbarFactory]);*/
  .controller('MainAppController', ['$scope', '$mooSnackbar', MainAppControllerFn]);
 /* .service('$mdCompiler', mdCompilerService)
 .factory('$mooSnackbar', ['$document', '$rootScope', '$q', '$compile', '$timeout', '$rootElement', '$animate', '$mdCompiler', MooSnackbarFactory]);*/

function MainAppControllerFn($scope, $mooSnackbar) {
  $scope.array = [1, 2, 3, 4, 5, 6];
  $scope.hello = "Hi I'm a Sexy Snackbar";
  $scope.show = function showFn($event) {
    $mooSnackbar.show({
      preserveScope: true,
      scope: $scope,
      template: `<snackbar class="Snackbar bottom" ng-click="snackbar.resolve()"><h1>{{hello}}</h1></snackbar>`,
      controller: /* @ngInject */ function mdToastCtrl($scope, $mooSnackbar) {
        debugger;
        var vm = this;

        vm.resolve = function() {
          $mooSnackbar.hide();
        };
      },
      controllerAs: 'snackbar',
      bindToController: true
    });
  };

  $scope.hide = function hideFn($event) {
    $mooSnackbar.hide();
  }
}

function MooSnackbarFactory($document, $rootScope, $q, $compile, $timeout, $rootElement, $animate, $mdCompiler) {
  let snackbarEventStack = [],
    service;

  return service = {
    show: show,
    cancel: cancel,
    hide: hide
  };

  function show(options) {
    if (snackbarEventStack.length) {
      return service.cancel().then(function() {
        debugger;
        return show(options);
      });
    } else {
      var interimElement = new InterimElement(options);
      snackbarEventStack.push(interimElement);
      return interimElement.show().then(function() {
        return interimElement.deferred.promise;
      });
    }
  }

  function hide(response) {
    var interimElement = snackbarEventStack.shift();
    return interimElement && interimElement.remove().then(function() {
      interimElement.deferred.resolve(response);
    });
  }

  function cancel(reason) {
    var interimElement = snackbarEventStack.shift();
    return $q.when(interimElement && interimElement.remove().then(function() {
      interimElement.deferred.reject(reason);
    }));
  };

  function InterimElement(options) {
    var self;
    var hideTimeout, element, showDone, removeDone;

    options = options || {};
    options = angular.extend({
      preserveScope: false,
      scope: options.scope || $rootScope.$new(options.isolateScope),
      onShow: function(scope, element, options) {
        return $animate.enter(element, options.parent);
      },
      onRemove: function(scope, element, options) {
        // Element could be undefined if a new element is shown before
        // the old one finishes compiling.
        return element && $animate.leave(element) || $q.when();
      }
    }, options);

    if (options.template) {
      options.template = angular.identity(options.template);
    }

    return self = {
      options: options,
      deferred: $q.defer(),
      show: function() {
        var compilePromise;
        if (options.skipCompile) {
          compilePromise = $q(function(resolve) {
            resolve({
              locals: {},
              link: function() {
                return options.element;
              }
            });
          });
        } else {
          compilePromise = $mdCompiler.compile(options);
        }

        return showDone = compilePromise.then(function(compileData) {
          angular.extend(compileData.locals, self.options);

          element = compileData.link(options.scope);

          // Search for parent at insertion time, if not specified
          if (angular.isFunction(options.parent)) {
            options.parent = options.parent(options.scope, element, options);
          } else if (angular.isString(options.parent)) {
            options.parent = angular.element($document[0].querySelector(options.parent));
          }

          // If parent querySelector/getter function fails, or it's just null,
          // find a default.
          if (!(options.parent || {}).length) {
            options.parent = $rootElement.find('body');
            if (!options.parent.length) options.parent = $rootElement;
          }
          var ret = options.onShow(options.scope, element, options);
          return $q.when(ret)
            .then(function() {
              // Issue onComplete callback when the `show()` finishes
              (options.onComplete || angular.noop)(options.scope, element, options);
              startHideTimeout();
            });

          function startHideTimeout() {
            if (options.hideDelay) {
              hideTimeout = $timeout(service.cancel, options.hideDelay);
            }
          }
        }, function(reason) {
          showDone = true;
          self.deferred.reject(reason);
        });
      },
      cancelTimeout: function() {
        if (hideTimeout) {
          $timeout.cancel(hideTimeout);
          hideTimeout = undefined;
        }
      },
      remove: function() {
        self.cancelTimeout();
        return removeDone = $q.when(showDone).then(function() {
          var ret = element ? options.onRemove(options.scope, element, options) : true;
          return $q.when(ret).then(function() {
            if (!options.preserveScope) options.scope.$destroy();
            removeDone = true;
          });
        });
      }
    };
  }

}

function mdCompilerService($q, $http, $injector, $compile, $controller, $templateCache) {

  /*
   * @ngdoc service
   * @name $mdCompiler
   * @module material.core
   * @description
   * The $mdCompiler service is an abstraction of angular's compiler, that allows the developer
   * to easily compile an element with a templateUrl, controller, and locals.
   *
   * @usage
   * <hljs lang="js">
   * $mdCompiler.compile({
   *   templateUrl: 'modal.html',
   *   controller: 'ModalCtrl',
   *   locals: {
   *     modal: myModalInstance;
   *   }
   * }).then(function(compileData) {
   *   compileData.element; // modal.html's template in an element
   *   compileData.link(myScope); //attach controller & scope to element
   * });
   * </hljs>
   */

  /*
   * @ngdoc method
   * @name $mdCompiler#compile
   * @description A helper to compile an HTML template/templateUrl with a given controller,
   * locals, and scope.
   * @param {object} options An options object, with the following properties:
   *
   *    - `controller` - `{(string=|function()=}` Controller fn that should be associated with
   *      newly created scope or the name of a registered controller if passed as a string.
   *    - `controllerAs` - `{string=}` A controller alias name. If present the controller will be
   *      published to scope under the `controllerAs` name.
   *    - `template` - `{string=}` An html template as a string.
   *    - `templateUrl` - `{string=}` A path to an html template.
   *    - `transformTemplate` - `{function(template)=}` A function which transforms the template after
   *      it is loaded. It will be given the template string as a parameter, and should
   *      return a a new string representing the transformed template.
   *    - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
   *      be injected into the controller. If any of these dependencies are promises, the compiler
   *      will wait for them all to be resolved, or if one is rejected before the controller is
   *      instantiated `compile()` will fail..
   *      * `key` - `{string}`: a name of a dependency to be injected into the controller.
   *      * `factory` - `{string|function}`: If `string` then it is an alias for a service.
   *        Otherwise if function, then it is injected and the return value is treated as the
   *        dependency. If the result is a promise, it is resolved before its value is 
   *        injected into the controller.
   *
   * @returns {object=} promise A promise, which will be resolved with a `compileData` object.
   * `compileData` has the following properties: 
   *
   *   - `element` - `{element}`: an uncompiled element matching the provided template.
   *   - `link` - `{function(scope)}`: A link function, which, when called, will compile
   *     the element and instantiate the provided controller (if given).
   *   - `locals` - `{object}`: The locals which will be passed into the controller once `link` is
   *     called. If `bindToController` is true, they will be coppied to the ctrl instead
   *   - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in
   */
  this.compile = function(options) {
    debugger;
    var templateUrl = options.templateUrl;
    var template = options.template || '';
    var controller = options.controller;
    var controllerAs = options.controllerAs;
    var resolve = options.resolve || {};
    var locals = options.locals || {};
    var transformTemplate = options.transformTemplate || angular.identity;
    var bindToController = options.bindToController;

    // Take resolve values and invoke them.  
    // Resolves can either be a string (value: 'MyRegisteredAngularConst'),
    // or an invokable 'factory' of sorts: (value: function ValueGetter($dependency) {})
    angular.forEach(resolve, function(value, key) {
      if (angular.isString(value)) {
        resolve[key] = $injector.get(value);
      } else {
        resolve[key] = $injector.invoke(value);
      }
    });
    //Add the locals, which are just straight values to inject
    //eg locals: { three: 3 }, will inject three into the controller
    angular.extend(resolve, locals);

    if (templateUrl) {
      resolve.$template = $http.get(templateUrl, {
          cache: $templateCache
        })
        .then(function(response) {
          return response.data;
        });
    } else {
      resolve.$template = $q.when(template);
    }

    // Wait for all the resolves to finish if they are promises
    return $q.all(resolve).then(function(locals) {

      var template = transformTemplate(locals.$template);
      var element = angular.element('<div>').html(template.trim()).contents();
      var linkFn = $compile(element);

      //Return a linking function that can be used later when the element is ready
      return {
        locals: locals,
        element: element,
        link: function link(scope) {
          locals.$scope = scope;

          //Instantiate controller if it exists, because we have scope
          if (controller) {
            var ctrl = $controller(controller, locals);
            if (bindToController) {
              angular.extend(ctrl, locals);
            }
            //See angular-route source for this logic
            element.data('$ngControllerController', ctrl);
            element.children().data('$ngControllerController', ctrl);

            if (controllerAs) {
              scope[controllerAs] = ctrl;
            }
          }

          return linkFn(scope);
        }
      };
    });

  };
}
              
            
!
999px

Console