2017-10-04 16 views
19

Changelog nói:góc thay đổi 5 Breaking - bằng tay nhập khẩu locale

By default Angular now only contains locale data for the language en-US, if you set the value of LOCALE_ID to another locale, you will have to import new locale data for this language because we don’t use the intl API anymore.

Nhưng tôi không thể tìm thấy bất kỳ tài liệu tham khảo những gì "nhập khẩu" có nghĩa là, làm thế nào để làm điều đó và tôi nhận được

xxx.html:30 ERROR Error: Missing locale data for the locale "de-CH"

tôi cấu hình locale với:

import { LOCALE_ID } from '@angular/core'; 

providers: [ 
    { provide: LOCALE_ID, useValue: 'de-CH' } 
    ], 
+0

điều duy nhất tôi có thể đoán nó kiễu góc (v 5) vẫn còn ở đầu RC tài liệu có thể cập nhật –

Trả lời

29

Điều này thực sự khó tìm trong phiên bản hiện tại :(. Dưới đây là những gì tôi đã phát hiện ra:

Các miền địa phương khác nhau nằm trong gói @angular/common/locales/. Trong trường hợp của bạn là:

import localeDECH from '@angular/common/locales/de-CH'; 

Bây giờ bạn cần phải đăng ký định nghĩa miền địa phương này trong dự án của bạn. Có một chức năng gọi là registerLocaleData được đặt tại: @angular/common.

Vì vậy, mã của bạn trong app.module.ts của bạn sẽ giống như thế này:

import {LOCALE_ID} from '@angular/core'; 
import { registerLocaleData } from '@angular/common'; 
import localeDECH from '@angular/common/locales/de-CH'; 

registerLocaleData(lcoaleDECH); 

@NgModule({ 
... 
providers: [ 
    { provide: LOCALE_ID, useValue: 'de-ch' }, 
] 
... 
}) 
.... 
3

Đối

{ provide: LOCALE_ID, useValue: 'pt-BR' } 

Sử dụng:

import { registerLocaleData } from '@angular/common'; 
import localePt from '@angular/common/locales/pt'; 
registerLocaleData(localePt); 
+0

Làm việc như một sự quyến rũ, cảm ơn! –

Các vấn đề liên quan