ngx-translate: How to translate dynamically array of strings

Discussão em 'Angular' iniciado por Damian Zakuro, Março 11, 2025.

  1. I want to create list of days of the week with ngx-translate, but it's not working with async pipe. I've got error "error TS2769: No overload matches this call." I have to use JSON file.

    TS:

    MON:Observable<string> = this.translate.get('CALENDAR.MON');
    TUE:Observable<string> = this.translate.get('CALENDAR.TUE');
    WED:Observable<string> = this.translate.get('CALENDAR.WED');
    THU:Observable<string> = this.translate.get('CALENDAR.THU');
    FRI:Observable<string> = this.translate.get('CALENDAR.FRI');
    SAT:Observable<string> = this.translate.get('CALENDAR.SAT');
    SUN:Observable<string> = this.translate.get('CALENDAR.SUN');



    daysOfWeeks:string[] = [`${this.MON}`, `${this.TUE}`, `${this.WED}`, `${this.THU}`, `${this.FRI}`, `${this.SAT}`, `${this.SUN}`];

    constructor(
    public translate: TranslateService
    ) { }


    HTML:

    <div *ngFor="let day of daysOfWeeks">{{ day | async}}</div>


    I also tried use pipe directly into ngFor but still doesn't work.

    Continue reading...

Compartilhe esta Página