Bastien Donjon

Développeur web à Bordeaux

Monthly Archive: September 2016

Friday

9

September 2016

0

COMMENTS

Set local default on your Angular 2 RC6 app

Written by , Posted in Javascript, typescript

Juste set LOCALE_ID in your app.module.ts file :

import {NgModule, ReflectiveInjector, LOCALE_ID}      from '@angular/core';

@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
routing
],
declarations: [
AppComponent,
],
providers: [
{provide: LOCALE_ID, useValue: 'fr-FR'},
BaseRequestOptions
],
bootstrap: [AppComponent]
})

Tuesday

6

September 2016

0

COMMENTS

Round number with Angular 2, pipe and Typescript

Written by , Posted in Javascript, typescript

// round.pipe.ts
import {Pipe, PipeTransform} from "@angular/core";

/**
 *
 */
@Pipe({name: 'round'})
export class RoundPipe implements PipeTransform {
    /**
     *
     * @param value
     * @returns {number}
     */
    transform(value: number): number {
        return Math.round(value);
    }
}
// app.module.ts
@NgModule({
    imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        routing
    ],
    declarations: [
        AppComponent,
        RoundPipe
    ],
    providers: [
        BaseRequestOptions
    ],
    bootstrap: [AppComponent]
})
<!-- exemple -->
<span>{{ yournumber | round }}</span>

Builded with TypeScript 1.8 for Angular 2.RC5