Angular $localize is not a function

Discussão em 'Angular' iniciado por Real World, Setembro 13, 2024.

  1. Real World

    Real World Guest

    I've got a strange error trying to use $localize in my ts files. I am getting this error


    Error: Uncaught (in promise): TypeError: angular_localize_init__WEBPACK_IMPORTED_MODULE_3_.$localize is not a function TypeError: angular_localize_init__WEBPACK_IMPORTED_MODULE_3_.$localize is not a function
    ​

    I have localisation working in my template files and there are no errors calling ng build. The error is at runtime when the component containing the $localize method is called. My ts code is

    private handleServerErrors(error: HttpErrorResponse): void {
    // Handle errors
    this.complete = true;
    switch (error.status) {

    ...

    case 500:
    default:
    // Could not update user
    this.errorMessage = $localize`:mad:@CalmBreathing_Desc_Short:Cobblers`;
    break;
    }
    console.error(error);
    }


    The polyfills.ts file has this at the top

    /***************************************************************************************************
    * Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
    */
    import '@angular/localize/init';


    This is Angular 11.2.8 with nodejs 12. Any ideas?

    Continue reading...

Compartilhe esta Página