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

              
                <h1>Angular 2.0 + ES6<br />Pomodoro Timer</h1>

<app></app>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Lato:300,400,700,900);
body{
  font-family: "Lato";
  font-weight: 300;
  color: #666;
}
h1{
  color: FireBrick;
}

hr{
  border: none;
  border-top: 2px solid FireBrick;
  margin: 30px 0px;
  width: 215px;
  opacity: 0.5;
}
input, button{
  font-family: "Lato";
  font-weight: 700;
  font-size: 14px;
  color: #555;
  border-radius: 2px;
  background: white;
  border: 2px solid #ddd;
  padding: 5px;
  margin-top: 10px;
}
input{
  width: 200px;
}
strong, button{
  font-family: "Lato";
  text-transform: uppercase;
  font-weight: 700;
}
button{
  margin-right: 10px;
  width: 100px;
}

              
            
!

JS

              
                // ANGULAR 2 without DECORATORS.
// Single file, no imports = works in Codepen, too...


// Trying things the "traditional Angular way" - the model is a service, no PubSub here

// Testing a singleton; this service will share one model for all components:
let TimerServiceInstance = null;
class TimerService{
  constructor(){
    if(!TimerServiceInstance){
      this.timer = {time: 1500, formattedTime: "25:00"};
      TimerServiceInstance = this;
    }
    return TimerServiceInstance;
  }
  myCounterId: int;
  
  reset(){ 
    clearInterval(myCounterId);
    this.timer.time = 1500; //time in seconds
    this.timer.formattedTime = "25:00";
  }

  start(){
  
    myCounterId = setInterval(() => {            
          //  this.timer.time--;
      this.count();
        }, 1000);
  }
  
  count(){
    this.timer.time = this.timer.time - 1;
    this.timer.formattedTime = this.convert();
    if (this.timer.time == 0) {
      var wav = 'http://www.oringz.com/oringz-uploads/sounds-917-communication-channel.mp3';
      var audio = new Audio(wav);
			audio.play();
      clearInterval(myCounterId);
    }   
  }

  change(length){
    this.timer.time = length;
    this.timer.formattedTime = this.convert();
  }

convert(){
    var minutes = parseInt( this.timer.time / 60 ) % 60;
    var seconds = this.timer.time % 60;
    return (minutes + ":" + seconds);
}
  
}

let TimerView = `
<div>
  <hr>
  <input type="text"
    placeholder="Pomodoro length (seconds)"
    [value]="timer.time"
    #time
    (change)="timeChanged(time)"
    (input)="timeChanged(time)"
    >
  </input>
  <p><strong>{{timer.time}}</strong></p>
  <p><strong>{{timer.formattedTime}}</strong></p>
  <button (click)="start()">Start</button>
  <button (click)="reset()">Reset</button>
</div>
`;


class Timer {
  
  constructor(TimerService) {
    this.timerService = TimerService;
    this.timer = TimerService.timer;
  }
  
  reset(){
    this.timerService.reset();
  }
  
  start(){
  this.timerService.start();
 } 
  
  timeChanged(time){
    this.timerService.change(time.value);
  }
      
}

class App{
  constructor(){
    
  }
}

let AppView = `
<div>
  <timer></timer>
</div>
`


// THIS IS ALL that is needed for Angular specific code:
makeComponent({
  view: AppView,
  controller: App,
  directives: [Timer]
});
makeComponent({
  view: TimerView,
  controller: Timer,
  injects: [TimerService]
});

// A decorator function:
function makeComponent(conf){
  // Conventions; use controller name if no selector is given:
  let selector = conf.selector ? conf.selector : conf.controller.name;
  conf.controller.annotations = [
    new ng.ComponentAnnotation({
      selector: selector,
      viewInjector: conf.injects
    }),
    new ng.ViewAnnotation({
      template: conf.view,
      directives: conf.directives
    })
  ]
  if(conf.injects)
    conf.controller.parameters = [conf.injects];
}

// Boot
document.addEventListener('DOMContentLoaded', () => {
  ng.bootstrap(App);
});
              
            
!
999px

Console