From ec051c5e8531032dc41cf08ccb2b42ec45948f74 Mon Sep 17 00:00:00 2001 From: Roberto Simonetti Date: Wed, 10 Aug 2016 22:57:20 +0200 Subject: [PATCH] Update documentation --- README.md | 2 +- doc/spec.md | 70 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 48d36f88..4534016e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Because it is only a branch of Angular 2, the goal is the complete integration w Get the changelog by [releases](https://github.com/robisim74/angular2localization/releases). -Compatible with Angular 2.0.0-rc.4. +Compatible with Angular 2.0.0-rc.5. ## Installing You can add `angular2localization` to your project using `npm`: diff --git a/doc/spec.md b/doc/spec.md index d74cd1d5..f4da358d 100644 --- a/doc/spec.md +++ b/doc/spec.md @@ -1,5 +1,5 @@ # Angular 2 Localization library specification -Library version: 0.8.9 +Library version: 0.8.10 ## Table of contents * [1 The library structure](#1) @@ -221,6 +221,17 @@ export class AppComponent extends Locale { } ``` +Instead of in each component, you can also declare the use of the pipes once in `NgModule`, for example: +```TypeScript +@NgModule({ + ... + declarations: [ + ... + TranslatePipe + ], + ... +}) +``` ### 2.4 List Now you can localize a list simply. For example: @@ -277,6 +288,16 @@ export class AppComponent { } ``` +You can also avoid adding the `providers` in the route component, and instead use `NgModule`: +```TypeScript +@NgModule({ + ... + providers: [ + LocaleService + ], + ... +}) +``` ### 3.2 Second scenario: you only need to translate messages Add in the route component in order to access the data of location from anywhere in the application: @@ -305,9 +326,19 @@ export class AppComponent { } ``` -Also add in the main: +In `NgModule`, import `HttpModule`, and if you want to avoid adding the `providers` in the route component: ```TypeScript -bootstrap(AppComponent, [HTTP_PROVIDERS]); +@NgModule({ + imports: [ + HttpModule + ], + ... + providers: [ + LocaleService, + LocalizationService + ], + ... +}) ``` #### 3.2.1 Direct loading @@ -560,7 +591,7 @@ and the code of the component is the following: ```TypeScript import { Component } from '@angular/core'; // FormBuilder with formControl. -import { FORM_DIRECTIVES, REACTIVE_FORM_DIRECTIVES, FormBuilder, FormGroup, AbstractControl } from '@angular/forms'; +import { FormBuilder, FormGroup, AbstractControl } from '@angular/forms'; // Angular 2 Material. import { MD_CARD_DIRECTIVES, @@ -570,15 +601,14 @@ import { // Services. import { Locale, LocaleService, LocalizationService, LocaleParser } from 'angular2localization/angular2localization'; // Pipes. -import { TranslatePipe } from 'angular2localization/angular2localization'; import { LocaleDecimalPipe } from 'angular2localization/angular2localization'; // Directives for FormBuilder with formControl. import { LocaleNumberValidator, validateLocaleNumber } from 'angular2localization/angular2localization'; @Component({ templateUrl: './app/validation.component.html', - pipes: [TranslatePipe, LocaleDecimalPipe], - directives: [FORM_DIRECTIVES, REACTIVE_FORM_DIRECTIVES, LocaleNumberValidator, MD_CARD_DIRECTIVES, MD_INPUT_DIRECTIVES, MdButton] + pipes: [LocaleDecimalPipe], + directives: [LocaleNumberValidator, MD_CARD_DIRECTIVES, MD_INPUT_DIRECTIVES, MdButton] }) export class ValidationComponent extends Locale { @@ -595,7 +625,7 @@ export class ValidationComponent extends Locale { decimal: AbstractControl; constructor(public locale: LocaleService, public localization: LocalizationService, private fb: FormBuilder) { - super(locale, localization) + super(locale, localization); this.numberForm = fb.group({ 'decimal': ['', validateLocaleNumber(this.locale, this.digits, this.minValue, this.maxValue)] @@ -614,6 +644,26 @@ export class ValidationComponent extends Locale { } ``` +Finally, import `ReactiveFormsModule` in `NgModule`: +```TypeScript +@NgModule({ + imports: [ + ... + FormsModule, + ReactiveFormsModule, + ... + ], + declarations: [ + ... + TranslatePipe + ], + providers: [ + LocaleService, + LocalizationService + ], + ... +}) +``` ## 7 Services API @@ -680,7 +730,7 @@ Method | Function `static NumberFormat(defaultLocale: string): boolean;` | Support for numbers `static Collator(lang: string): boolean;` | Support for Collator -## Appendix A - Angular-CLI settings +## Appendix A - Angular-CLI settings up to 1.0.0-beta.10 Install the library: ``` npm install --save angular2localization @@ -709,7 +759,7 @@ const packages: any = { }; ``` -## Appendix B - Using Ionic 2 +## Appendix B - Using Ionic 2 up to 2.0.0-beta.11 Install the library: ```Shell npm install --save angular2localization