How to display the currency symbol to the right in Angular

前端 未结 8 1394
花落未央
花落未央 2020-12-15 04:37

I have to display Euro currency like this : 583 €.

But with this code:

{{ price | currency:\'EUR\':true }}

I get

8条回答
  •  悲&欢浪女
    2020-12-15 05:00

    I was looking to this answer, and the current version of angular it is possible to define providers for localization and Default currency code.

    Like this.

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule, LOCALE_ID, DEFAULT_CURRENCY_CODE } from '@angular/core';
    
    import localePt from '@angular/common/locales/pt';
    import { registerLocaleData } from '@angular/common';
    
    // Register the localization
    registerLocaleData(localePt, 'pt-BR');
    
    @NgModule({
      declarations: [
        AppComponent,
        NotificationListComponent
      ],
      imports: [
        BrowserModule,
        FormsModule,
        ReactiveFormsModule,
        HttpClientModule,
      ],
      providers: [
        {
          provide: LOCALE_ID,
          useValue: 'pt-BR'
         },
         {
           provide: DEFAULT_CURRENCY_CODE,
           useValue: 'BRL'
         },
        DataService,
        NotificationsService,
        GeoLocationService,
      ],
      entryComponents: components,
    })
    

    Once done, the utilization is very simple:

    Gst
    -{{offers.contentInsurance | currency}}

    It is not necessary to create any custom pipeline or different custom action.

提交回复
热议问题