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

              
                <my-app></my-app>
              
            
!

CSS

              
                .grow {
  font-size: 1.5em;
}

.justify {
  justify-content: center;
}

              
            
!

JS

              
                // app.js


console.log(ng)

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

const { FormsModule } = ng.forms;

@Component({
  selector: 'my-app',
  template: `
      <div class="jumbotron text-center">
        <h3>{{title}} 🇧🇷</h3>
        <div class="justify form-inline">
          <span class="form-group" [ngClass]="{'d-none': editNumber}" >
            <b (click)="this.edit()" 
               class="form-control badge badge-primary grow">
             {{number | formatNumber: format}}
            </b>
          </span>
          <span class="form-group" [ngClass]="{'d-none': !editNumber}">
            <input type="number"
              class="form-control"
               [(ngModel)]="number" 
                placeholder="000" 
                (blur)="this.edit()" />
          </span>
          <span class="form-group">
            <select class="form-control"
               [(ngModel)]="format" >
                <option di value="">Select</option>
                <option value="1.0M" >1M</option>
                <option value="$1.00M" >$1M</option>
                <option value="$100.00" >$1.00</option>
            </select>
          </span>
        </div>
      </div>
`
})
class AppComponent {  
  title="Fun Numbers with Angular " + VERSION.major;
  test = d3.format('~s')(1000000)
  number: number
  format: string
  editNumber: boolean
  constructor() {
    // TODO: Define your Angular component implementation
    this.number = 1500000
    this.format = ''
    this.editNumber = false
  }
  
  edit () {
    this.editNumber = !this.editNumber
  }
}

class Format {
  constructor () {}
  number (n, f) {
    
    const format = f || '1.0M'
    
    let number
    
    // Put business logic here
    console.log('f', format)
    switch (format) {
      case '$1.00M':
        number = d3.format('$.2s')(n)
        break
      case '$100.00':
        number = d3.format('$,.2f')(n)
        break
      case '1.0M':
        if (/\.0/.test(d3.format('.2s')(n))) {
          number = d3.format('~s')(n)
        } else {
          number = d3.format('.2s')(n)
        }
        break
      default:
        number = d3.format(format)(n)
    }
    
    console.log('run', [n, number, f])
    
    return number.replace(/G/, "B").toUpperCase()
  }
}

@Pipe({name: 'formatNumber'})
class formatNumber implements PipeTransform {
  format = new Format()
  transform(value: number, format?: string): number {
    return this.format.number(value, format)
  }
}

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

@NgModule({
  imports: [
    BrowserModule,
    CommonModule,
    FormsModule
  ],
  declarations: [AppComponent, formatNumber],
  bootstrap: [AppComponent],
  providers: []
})
class AppModule {}

const { platformBrowserDynamic } = ng.platformBrowserDynamic; 

platformBrowserDynamic()
  .bootstrapModule(AppModule)
  .catch(err => console.error(err));

console.log('hola');


              
            
!
999px

Console