TranslocoCurrencyPipe NullInjectorError

I am currently trying to upgrade the Transloco version in our project. Previously we were on Transloco 4.3.0 and Transloco-MessageFormat 4.1.0.
The goal ist to upgrade them to the newest version (7).

As stated in the breaking changed for v5, I changes the way of providing, as the new way should be. See TranslocoRootModule:

@NgModule({
    imports: [],
    exports: [TranslocoModule],
    providers: [
        provideTransloco(
            {
                config: {
                    availableLangs: ['de', 'en'],
                    defaultLang: 'de',
                    missingHandler: {
                        allowEmpty: true,
                    },
                    reRenderOnLangChange: true,
                    prodMode: false,
                },
                loader: TranslocoHttpLoader
            }
        ),
        provideTranslocoMissingHandler(TranslocoCustomMissingHandler),
        provideTranslocoMessageformat({locales: ['de-DE']}),
        provideTranslocoLocale({defaultLocale: 'de-DE'}),
    ],
})
export class TranslocoRootModule { ... }

As it stands, the TranslocoCurrenyPipe is working perfectly fine with in-template use. But in some occasions we also need to use the pipe within the ts file of a component or a service. Which worked perfectly fine before upgrading. See:

constructor(
    private readonly currencyPipe: TranslocoCurrencyPipe
) { ... }

const priceStr = `${this.currencyPipe.transform(
    price,
    'symbol',
    { minimumFractionDigits: 0, maximumFractionDigits: 0 },
    data.price.total.currency,
)}`;

This implementation now leads to an Error being thrown in the Browser (Regarding the new standalone way?). See:

ERROR NullInjectorError: R3InjectorError(AppModule)[GoogleMapsService -> TranslocoCurrencyPipe -> ChangeDetectorRef -> ChangeDetectorRef]: 
  NullInjectorError: No provider for ChangeDetectorRef!
    at NullInjector.get (core.mjs:1662:27)
    at R3Injector.get (core.mjs:3108:33)
    at R3Injector.get (core.mjs:3108:33)
    at injectInjectorOnly (core.mjs:1106:40)
    at ɵɵinject (core.mjs:1112:60)
    at inject (core.mjs:1198:12)
    at <instance_members_initializer> (jsverse-transloco-locale.mjs:878:17)
    at new BaseLocalePipe (jsverse-transloco-locale.mjs:876:1)
    at new TranslocoCurrencyPipe (jsverse-transloco-locale.mjs:897:1)
    at BaseLocalePipe_Factory (jsverse-transloco-locale.mjs:890:16)

I know this is pretty few. I sadly can’t get it done to build you guys sample project, since I am not able to set it up the same way, that it leads to the same error. I tried to, but failed along that way sadly.
Also it is not possible to share the whole project with you, due to some restrictions.

So this is more like a hail mary, hoping that you guys maybe see the issue from these informations as an act of desperation. Maybe you can help.
I can provide further information if needed.

Under the hood the currency pipe uses the TranslocoLocaleService. In TypeScript code, it is better practice to directly use the service instead of injecting the pipe. You can check out the API of the service in the docs. Updated code:

export class MyComponent {
  constructor(private readonly localeService: TranslocoLocaleService) {}

  getPrice(price: number, currency: string) {
    const priceStr = `${this.localeService.localizeNumber(
      price,
      'currency',
      undefined,
      {
        currency,
        minimumFractionDigits: 0,
        maximumFractionDigits: 0,
      },
    )}`;
  }
}

As you can see, this requires a bit of refactoring.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật