How to avoid characters in an Angular date tube?

I have an Angular date variable todaythat I use date pipe , for example:

{{today | date:'LLLL d'}}

February 13

However, I would like to do it as follows:

13 days until February

When I try to naively approach this, I get this result:

{{today | date:'d days so far in LLLL'}}

13 13PM201818 18o fPMr in February

This is because, for example, drefers to the day.

How can I escape these characters in an Angular date tube? I tried \dthis one too, but the result did not change with the added backslashes.

+4
source share
3 answers

How about this:

{{today | date:'d \'days so far in\' LLLL'}}

Everything inside single quotes is ignored. And do not forget to avoid them.

+3
source

, RichMcCluskey, , momentjs . , escape-, momentjs.

- , , , .

import { Inject, Pipe, PipeTransform } from '@angular/core';

@Pipe({ name: 'momentDate', pure: true })
export class MomentDatePipe implements PipeTransform {

    transform(value: any, pattern: string): string {
        if (!value)
            return '';
        return moment(value).format(pattern);
    }
}

:

{{today | momentDate:'d [days so far in] LLLL'}}

. .

, momentjs , cli, HTML (, index.html).

+1

, Angular . , , :

{{today | date:'d'}} days so far in {{today | date:'LLLL'}}

EDIT:

After posting this question, I tried @ Gh0sT's solution and it worked, so I guess there is a way to use one date channel.

+1
source

Source: https://habr.com/ru/post/1693602/


All Articles