Reputation: 757
I made a pipe to display monetary value in the Brazilian format. When squeegee everything works normally. However when running in a DEV / Prod environment on azure I get this message. The error also happens when it runs "ng serves --prod"
.
This is configuration in the module
import { LOCALE_ID } from '@angular/core';
import { registerLocaleData } from '@angular/common';
import localePt from '@angular/common/locales/pt';
registerLocaleData(localePt);
providers: [
{
provide: LOCALE_ID,
useValue: 'pt-PT'
}
],
PIPE AS HTML
{{produto.valorAntesPromocao | number:'1.2-2'}}
Error message :
InvalidPipeArgument: 'Missing locale data for the locale "pt-BR".' for pipe 'xl'
Upvotes: 11
Views: 19882
Reputation: 1
import { DEFAULT_CURRENCY_CODE, LOCALE_ID } from '@angular/core';
import ptBr from '@angular/common/locales/pt';
import { registerLocaleData } from '@angular/common';
registerLocaleData(ptBr);
providers: [
{
provide: LOCALE_ID,
useValue: 'pt',
},
{
provide: DEFAULT_CURRENCY_CODE,
useValue: 'BRL',
},
],
Isto Funcionou Perfeitamente para mim, Creditos ao nosso amigo @MarcosVidal
This Worked Perfectly for me, Credits to our friend @MarcosVidal
Upvotes: 0
Reputation: 19
This is how I've solved this problem:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { PostComponent } from './post/post.component';
//**************** imports here ****************
import { DEFAULT_CURRENCY_CODE, LOCALE_ID } from '@angular/core';
import ptBr from '@angular/common/locales/pt';
import { registerLocaleData } from '@angular/common';
// registerlocaledata
registerLocaleData(ptBr);
@NgModule({
declarations: [AppComponent, PostComponent],
imports: [BrowserModule],
//configuring providers.
providers: [
{
provide: LOCALE_ID,
useValue: 'pt',
},
{
provide: DEFAULT_CURRENCY_CODE,
useValue: 'BRL',
},
],
bootstrap: [AppComponent],
})
export class AppModule {}
Upvotes: 1
Reputation: 33
You can just use "pt" as provider value:
{
provide: LOCALE_ID,
useValue: 'pt'
}
According this thread on github, Angular uses "pt" for brazilian formats and "pt-pt" for the european portuguese.
Upvotes: 1
Reputation: 1143
Try in this way:-
import {LOCALE_ID} from '@angular/core';
import localePt from '@angular/common/locales/pt';
import {registerLocaleData} from '@angular/common';
registerLocaleData(localePt, 'pt');
@NgModule({
providers: [
{
provide: LOCALE_ID,
useValue: 'pt'
}
]
})
Upvotes: 7
Reputation: 222582
Can you try adding this way
import { LOCALE_ID } from '@angular/core';
import { registerLocaleData } from '@angular/common';
import localePt from '@angular/common/locales/pt';
registerLocaleData(localePt);
@NgModule({
providers: [
{ provide: LOCALE_ID, useValue: 'pt-BR' }
]
})
export class AppModule { }
Upvotes: 30