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

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

              
                <div ng-app="App">
  
  <component-one class="component" cmp-name="one">
    <p>This is a simple component that will output some message below.</p>
    <p>The message will come from the <strong>Store</strong>.</p>
  </component-one>
  
  <component-two class="component" cmp-name="two">
    <p>We send a simple string but we can send whatever data we need to communicate.</p>
    <p>Remember: <i>data is not hold by the component scope, just merely referenced to.</i> It still lives on the <strong>Store</strong>.</p>
  </component-two>
  
</div>
              
            
!

CSS

              
                body
  padding 10px
  
[ng-app]
  display flex
  flex-flow row wrap

.component
  flex 1 100%
  padding 10px
  margin 10px
  border 10px double
  background-color #fffffc
  
  pre
    white-space normal
  input
    border none
    border-bottom 1px dotted #666
    outline none
    width 100%
    font 16px/32px Monospace
    
  button
    margin 10px 0
 
  &[cmp-name="one"]
    border-color alpha(#00BFFF, 66%)
  &[cmp-name="two"]
    border-color alpha(#d33daa, 99%)

              
            
!

JS

              
                angular
// declare the main app
.module('App', [])
// declare the "store" or whatever name that make sense
// for you to call it (model, state, etc.)
.factory('Store', () => {
  // hold a local copy of the state, setting its defaults
  const state = {
    data: {
      msg: ''
    }
  };
  // local log for the undo/redo feature
  const log = {
    index: 0,
    count: 0,
    changes: [
      { msg: ''}
    ]
  };
  // expose basic getter and setter methods
  return {
    get() {
      return state.data;
    },
    set(data) {
      // save the previous state into log
      log.changes.push(data);
      log.count++;
      log.index = log.count;
      console.log('set called', log.count, log.index, data);
      Object.assign(state.data, data);
    },
    undo() {
      if (log.index > 0) {
         log.index--;
      }
      const data = log.changes[log.index];
      console.log('undo called', log.count, log.index, data);
      return Object.assign(state.data, data);
    },
    redo() {
      if (log.index < log.count) {
        log.index++;
      }
      const data = log.changes[log.index];
      console.log('redo called', log.count, log.index, data);
      return Object.assign(state.data, data);;
    }
  };
})
// declare some simple components to illustrate how this approach can works
.component('componentOne', {
  transclude: true,
  template: `
    <h1>Component "{{$ctrl.cmpName}}"</h1>
    <div ng-transclude></div>
    <b ng-show="$ctrl.state.msg">Message:</b>
    <pre>{{$ctrl.state.msg}}</pre>`,
  // inject the Store dependency
  controller(Store) {
    // get the store reference and bind it to the scope:
    // now, every change made to the store data will be 
    // automatically reflected into this scope property,
    // which enable us to build interactive components
    // that react to data changes.
    this.state = Store.get();
  },
  bindings: {
    cmpName: '@',
  }
})
.component('componentTwo', {
  transclude: true,
  template: `
    <h3>Component "{{$ctrl.cmpName}}"</h3>
    <div ng-transclude></div>
    <input ng-model="$ctrl.text" ng-change="$ctrl.onMessageChange()" placeholder="Send a message">
    <button ng-click="$ctrl.onUndo()">UNDO</button>
    <button ng-click="$ctrl.onRedo()">REDO</button>
    <p><i>Hint: look at the console to see the log.</i><p/>
`,
  // same here, we need the Store
  controller(Store) {
    // define the callback for the input change
    this.onMessageChange = () => {
      // BOOM! We just set the Store data.
      // No need to notify or anything!
      // (use at your own risk)
      Store.set({ msg: this.text });
    };
    
    this.onUndo = () => {
      this.text = Store.undo().msg;
    };
    
    this.onRedo = () => {
      this.text = Store.redo().msg;
    };
  },
  bindings: {
    cmpName: '@',
  },
});
              
            
!
999px

Console