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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

Screenshot or Custom Thumbnail

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

              
                <html ng-app="ionicApp">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

  <title>Ionic modal service</title>

  <link href="//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
  <script src="//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
</head>

<body ng-controller="AppCtrl as vm">

  <ion-content padding="true" ng-class="{'has-footer': showFooter}">
    <div class="row">
      <div class="col">
        <div class="button-bar">
          <button ng-click="vm.openContactDialog()" class="button button-assertive button-block">
            Open contacts to select
          </button>
          <button ng-click="vm.showSignInSignUp()" class="button button-positive button-block">
            Open Sign-in modal
          </button>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col">
        <div ng-if="vm.selectedContact">
          <h1 class="text-center">Selected:{{vm.selectedContact.name}}</h1>
        </div>
      </div>
    </div>

  </ion-content>

  <script id="contacts-modal.html" type="text/ng-template">
    <div class="modal">
      <ion-header-bar class="bar bar-header bar-positive">
        <h1 class="title">Contacts</h1>
        <button class="button button-clear button-primary" ng-click="vm.closeModal(vm.selectedContact)">Close</button>
      </ion-header-bar>
      <ion-content>
        <div class="item" ng-if="vm.selectedContact">
          <h1>Selected: {{vm.selectedContact.name}}</h1>
        </div>
        <ion-list class="list">
          <ion-item ng-repeat="contact in vm.contacts" ng-click="vm.confirmSelection(contact)">
            {{ contact.name }}
          </ion-item>
        </ion-list>
      </ion-content>
    </div>
  </script>
  <script id="confirm-contact-modal.html" type="text/ng-template">
    <div class="modal">
      <ion-header-bar class="bar bar-header bar-positive">
        <h1 class="title">Confirm contact</h1>
      </ion-header-bar>
      <ion-content>
        <button class="button button-positive button-block" ng-click="vm.confirm(vm.contact)">
          Confirm {{vm.contact.name}}
        </button>
        <button class="button button-primary button-block" ng-click="vm.cancel()">Cancel</button>
      </ion-content>
    </div>
  </script>

  <script id="sign-in-sign-up.html" type="text/ng-template">
    <ion-modal-view id="sign-in-sign-up"> {{vm.slideCtrl.setSlide();''}}
      <ion-slide-box delegate-handle="sign-in-sign-up" active-slide="vm.slideCtrl.index" auto-play="false" show-pager="false" slide-interval="" pager-click="" on-slide-changed="">
        <ion-slide class="sign-up">
          <ion-scroll>
            <div class="list">
              <div class="item">
                <button ng-click="vm.on.notReady('Facebook Connect')" class="button button-block button-positive light icon ion-social-facebook">&nbsp; Sign-up with Facebook</button>
              </div>
              <div class="item">
                <div class="text-center larger">&mdash; or &mdash;</div>
              </div>
              <div class="padding-horizontal">
                <form name="registerForm" novalidate="" ng-submit="vm.on.register(person, closeModal)">
                  <label class="item item-input"><i class="icon ion-person padding-horizontal larger"></i>
                    <input type="text" name="Username" placeholder="Username" ng-model="person.username" required="required" />
                  </label>
                  <label class="item item-input"><i class="icon ion-email padding-horizontal larger"></i>
                    <input type="text" name="Email" placeholder="Email" ng-model="person.email" required="required" />
                  </label>
                  <label class="item item-input"><i class="icon ion-locked padding-horizontal larger"></i>
                    <input type="password" name="Password" placeholder="Password" ng-model="person.password" required="required" />
                  </label>
                  <label class="item item-input hide"><i class="icon ion-locked padding-horizontal larger"></i>
                    <input type="password" name="PasswordRepeat" placeholder="Again" ng-model="person.passwordRepeat" />
                  </label>
                  <div class="item">
                    <div class="button-bar">
                      <button ng-click="closeModal('CANCELED')" class="button button-balanced button-outline">Cancel</button>
                      <button type="submit" class="button button-balanced">Sign up</button>
                    </div>
                  </div>
                  <div class="item positive">
                    <div class="text-right"> <a ng-click="vm.slideCtrl.setSlide('signin')">Have an account? Sign in <i class="icon ion-android-arrow-forward padding-right"></i></a></div>
                  </div>
                </form>
              </div>
            </div>
          </ion-scroll>
        </ion-slide>
        <ion-slide class="sign-in">
          <ion-scroll>
            <div class="list">
              <div class="item">
                <button ng-click="vm.on.notReady('Facebook Connect')" class="button button-block button-positive light icon ion-social-facebook">&nbsp; Sign-in with Facebook</button>
              </div>
              <div class="item">
                <div class="text-center larger">&mdash; or &mdash;</div>
              </div>
              <div class="padding-horizontal">
                <form name="signInForm" novalidate="" ng-submit="vm.on.signIn(person, closeModal);">
                  <label class="item item-input"><i class="icon ion-person padding-horizontal larger"></i>
                    <input type="text" name="Username" placeholder="Username" ng-model="person.username" required="required" />
                  </label>
                  <label class="item item-input"><i class="icon ion-locked padding-horizontal larger"></i>
                    <input type="password" name="Password" placeholder="Password" ng-model="person.password" required="required" />
                  </label>
                  <div class="item">
                    <div class="button-bar">
                      <button ng-click="closeModal('CANCELED')" class="button button-balanced button-outline">Cancel</button>
                      <button type="submit" class="button button-balanced">Sign in</button>
                    </div>
                  </div>
                  <div class="item positive text-left">
                    <div class="pull-right"><a ng-click="vm.on.notReady('password recovery')">Forgot Password?</a></div><a ng-click="vm.slideCtrl.setSlide('signup')"><i class="icon ion-android-arrow-back padding-left"></i> Sign up</a>
                  </div>
                </form>
              </div>
            </div>
          </ion-scroll>
        </ion-slide>
      </ion-slide-box>
    </ion-modal-view>
  </script>

</body>

</html>
              
            
!

CSS

              
                .pull-right {
  float: right;
}
              
            
!

JS

              
                angular.module('ionicApp', ['ionic'])
  .controller('ConfirmContactDialogCtrl', ['$scope', 'parameters', function($scope, parameters) {
    var vm = this;
    vm.contact = parameters;
    vm.confirm = function(contact) {
      $scope.closeModal(contact);
    };
    vm.cancel = function() {
      $scope.closeModal(null);
    };
  }])
  .controller('ContactDialogCtrl', ['$scope', 'parameters', 'myModals', function($scope, parameters, myModals) {
    var vm = this;
    vm.contacts = [{
      name: 'Gordon Freeman'
    }, {
      name: 'Barney Calhoun'
    }, {
      name: 'Lamarr the Headcrab'
    }, ];
    vm.selectedContact;
    if (parameters && parameters.length !== 0) {
      vm.contacts.push(parameters);
    }

    vm.confirmSelection = function(selected) {
      if (selected) {
        myModals.showConfirmContact(selected)
          .then(function(result) {
            if (result) {
              vm.selectedContact = result;
            }
          });
      }

    };

  }])
.controller('SignInModalCtrl', ['$scope', 'parameters', 'myModals', '$q', '$timeout', function($scope, parameters, myModals, $q, $timeout) {
    var vm = this;
    vm.slideCtrl = {
      /*
      * NOTE: ionSlideBox evaluates active_slide=slideCtrl.index BEFORE ionic.views.Slider.setup() is complete, you get an Exception if the active_slide is anything but 0
      */
      index: null,
      slideLabels: ['signup', 'signin'],
      initialSlide: 'signin',
      setSlide: function(label) {
        var i, next, slideCtrl = vm.slideCtrl;
        if (slideCtrl.index === null) {
          $timeout(function() {
            if (!label) {
              label = slideCtrl.initialSlide;
            }
            return slideCtrl.setSlide(label);
          });
          return slideCtrl.index = 0;
        }
        if (label == null) {
          return slideCtrl.index;
        }
        if (label === 'initial') {
          label = slideCtrl.initialSlide;
        }
        i = slideCtrl.slideLabels.indexOf(label);
        next = i >= 0 ? i : slideCtrl.index;
        return slideCtrl.index = next;
      }
    };
    vm.on = {
      notReady: function(value) {
        console.log("Sorry, " + value + " is not available yet");
        return false;
      },
      signIn: function(person, fnComplete) {
        console.log("signIn with data=" + JSON.stringify(person));
        fnComplete(person);
      },
      register: function(person, fnComplete) {
        console.log("register with data=" + JSON.stringify(person));
        fnComplete(person);
      },
    }

  }])
  .controller('AppCtrl', ['$scope', 'myModals', '$q', function($scope, myModals, $q) {
    var vm = this;
    vm.selectedContact = '';
    vm.openContactDialog = function() {
      myModals.showContacts({
          name: 'Julian Paulozzi'
        })
        .then(function(result) {
          if (result && result.name) {
            vm.selectedContact = result;
          }
        }, function(err) {
          alert(err);
        });
    };
    vm.showSignInSignUp = function() {
      options = {
        person: {}
      }
      return myModals.showSignInSignUp(options)
        .then(function(result) {
          if (result == null || result === 'CANCELED') {
            return $q.reject('CANCELED');
          }
          if (result != null ? result['isError'] : void 0) {
            return $q.reject(result);
          }
          console.log(result)
          return result;
        });
    }

  }])
  .factory('myModals', ['appModalService', function(appModalService) {
    // all app modals here
    var service = {
      showConfirmContact: showConfirmContact,
      showContacts: showContacts,
      showSignInSignUp:showSignInSignUp
    };

    return service;

    function showConfirmContact(contact) {
      return appModalService.show('confirm-contact-modal.html', 'ConfirmContactDialogCtrl as vm', contact);
    }

    function showContacts(otherContact) {
      return appModalService.show('contacts-modal.html', 'ContactDialogCtrl as vm', otherContact);
    }
    
    function showSignInSignUp(params) {
      return appModalService.show('sign-in-sign-up.html', 'SignInModalCtrl as vm', params);
    }

  }])
  .factory('appModalService', ['$ionicModal', '$rootScope', '$q', '$injector', '$controller', function($ionicModal, $rootScope, $q, $injector, $controller) {

    return {
      show: show
    }

    function show(templeteUrl, controller, parameters, options) {
      // Grab the injector and create a new scope
      var deferred = $q.defer(),
        ctrlInstance,
        modalScope = $rootScope.$new(),
        thisScopeId = modalScope.$id,
        defaultOptions = {
          animation: 'slide-in-up',
          focusFirstInput: false,
          backdropClickToClose: true,
          hardwareBackButtonClose: true,
          modalCallback: null
        };

      options = angular.extend({}, defaultOptions, options);

      $ionicModal.fromTemplateUrl(templeteUrl, {
        scope: modalScope,
        animation: options.animation,
        focusFirstInput: options.focusFirstInput,
        backdropClickToClose: options.backdropClickToClose,
        hardwareBackButtonClose: options.hardwareBackButtonClose
      }).then(function(modal) {
        modalScope.modal = modal;

        modalScope.openModal = function() {
          modalScope.modal.show();
        };
        modalScope.closeModal = function(result) {
          deferred.resolve(result);
          modalScope.modal.hide();
        };
        modalScope.$on('modal.hidden', function(thisModal) {
          if (thisModal.currentScope) {
            var modalScopeId = thisModal.currentScope.$id;
            if (thisScopeId === modalScopeId) {
              deferred.resolve(null);
              _cleanup(thisModal.currentScope);
            }
          }
        });

        // Invoke the controller
        var locals = {
          '$scope': modalScope,
          'parameters': parameters
        };
        var ctrlEval = _evalController(controller);
        ctrlInstance = $controller(controller, locals);
        if (ctrlEval.isControllerAs) {
          ctrlInstance.openModal = modalScope.openModal;
          ctrlInstance.closeModal = modalScope.closeModal;
        }

        modalScope.modal.show()
          .then(function() {
            modalScope.$broadcast('modal.afterShow', modalScope.modal);
          });

        if (angular.isFunction(options.modalCallback)) {
          options.modalCallback(modal);
        }

      }, function(err) {
        deferred.reject(err);
      });

      return deferred.promise;
    }

    function _cleanup(scope) {
      scope.$destroy();
      if (scope.modal) {
        scope.modal.remove();
      }
    }

    function _evalController(ctrlName) {
      var result = {
        isControllerAs: false,
        controllerName: '',
        propName: ''
      };
      var fragments = (ctrlName || '').trim().split(/\s+/);
      result.isControllerAs = fragments.length === 3 && (fragments[1] || '').toLowerCase() === 'as';
      if (result.isControllerAs) {
        result.controllerName = fragments[0];
        result.propName = fragments[2];
      } else {
        result.controllerName = ctrlName;
      }

      return result;
    }

  }]);
              
            
!
999px
A Pen is worth a thousand docs.

Console