Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ add another resource


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


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.


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.


                <script src=""></script>
<script src=""></script>
<script src="[email protected]/bundles/core.umd.js"></script>
<script src=""></script>
<script src="[email protected]/bundles/http.umd.js"></script>
<script src="[email protected]/bundles/common.umd.js"></script>
<script src="[email protected]/bundles/router.umd.js"></script>
<script src="[email protected]/bundles/compiler.umd.js"></script>
<script src="[email protected]/bundles/platform-browser.umd.js"></script>
<script src="[email protected]/bundles/platform-browser-dynamic.umd.js"></script>
<script src="[email protected]/bundles/forms.umd.js"></script>





                // app.js

const { Component, VERSION, Pipe, PipeTransform } = ng.core;

  name: 'applyPure',
  pure: true // immutable (value) inputs & pure fn (function)
class ApplyPurePipe implements PipeTransform {

  transform(value: any, fn: Function): any {
    return fn(value);

  name: 'apply',
  pure: false // any (value) inputs & any fn (function)
class ApplyPipe implements PipeTransform {

  transform(value: any, fn: Function): any {
    return fn(value);


  selector: 'my-app',
  template: `
<label for="value">Input {{fromScale}}
  <input id="value" [value]="value" type="number" (input)="value = $" >

<button (click)="toggleScale()">Convert to {{toScale}}</button> | 1 kg = 2.204 lbs


<h3>With applyPure Pipe :(</h3>
<h4>Note: with applyPure pipe, the conversion pipe is only applied if input changes, not when only the scale toggles</h4>
<div style="font-size: x-large" [style.color]="(value > (value | applyPure: covertValue)?toScale == 'kg': toScale == 'lbs')?'green':'red'">
  {{value}} {{fromScale}} = {{value | applyPure: covertValue}} {{toScale}}
<h4>convertValue(input) is <strong>not a pure function </strong>it depends on component.toScale, which it closes over from outside (component.toScale)</h4>
<h4>If use it using <em>applyPure</em> pipe (pure = true), the pipe bindings will not be evaluated when the toScale changes on press of button as it detects input only</h4>

<h3>With apply Pipe :)</h3>
<h4>Note: with apply pipe, the conversion pipe is applied with standard change detection, which detects changes to both, input and the scale</h4>
<div style="font-size: x-large" [style.color]="(value > (value | apply: covertValue)?toScale == 'kg': toScale == 'lbs')?'green':'red'">
  {{value}} {{fromScale}} =  {{value | apply: covertValue}} {{toScale}}
<h4>We know convertValue(input) is <strong>not a pure function </strong> hence we are using it with apply pipe not <del>applyPure pipe</del></h4>
<h4>The <em>apply</em> pipe (pure = false), the pipe bindings will be evaluated when the toScale changes on press of button as well as on changes to input</h4>

class AppComponent  {

  value = 0;
  fromScale: 'kg' | 'lbs' = 'kg';
  toScale: 'kg' | 'lbs' = 'lbs';
  toggle = false;

  constructor() {}

  toggleScale() {
    this.toggle = !this.toggle;
    this.fromScale = this.toggle ?  'lbs' : 'kg';
    this.toScale = this.toggle ? 'kg' : 'lbs' ;

  covertValue = (number) => {
    return this.toScale === 'kg' ? number / 2.2 : number * 2.204;

// main.js
const { BrowserModule } = ng.platformBrowser;
const { NgModule } = ng.core;
const { CommonModule } = ng.common;
const { FormsModule } =  ng.forms

  imports: [
  declarations: [AppComponent, ApplyPipe, ApplyPurePipe],
  bootstrap: [AppComponent],
  providers: []
class AppModule {}

const { platformBrowserDynamic } = ng.platformBrowserDynamic; 

  .catch(err => console.error(err));