globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 602 forks source link

Integrate Globalize with Angular #916

Open eluchsinger opened 3 years ago

eluchsinger commented 3 years ago

Hi folks

I'm trying to get Globalize running on Angular and it seems to me that it's not so easy. I haven't found any full examples on how to do that and only some incomplete samples.

Basically, I have the following component, but I always get the following error currencyFormatter is not a function:

import { Component } from "@angular/core";
import { AuthenticationService } from "../services/AuthenticationService";
import { Router } from "@angular/router";
import likelySubtags from "cldr-data/supplemental/likelySubtags.json";
import * as cldr from "cldrjs";
import * as Globalize from "globalize";

@Component({
  selector: "app-index",
  templateUrl: "./index.component.html",
  styleUrls: ["./index.component.css"],
})
export class IndexComponent {
  currency = 123;
  formattedCurrency = "";

  constructor(
    private router: Router,
    private authService: AuthenticationService
  ) {
    Globalize.load(likelySubtags);
    const formatter = new Globalize("de").currencyFormatter("USD");
    this.formattedCurrency = formatter(Math.PI);
  }

}
mellis481 commented 1 year ago

@eluchsinger Did you find a solution to this?