When working with Angular 2+, you have the ability to iterate through data using *ngFor
. Starting from Angular 7, DatePipes for both Week of Year and Week of Month are supported.
According to the Angular documentation on DatePipe:
Week of year: w
Week of month: W
Here's an example on StackBlitz
To display the week of the month:
<h3>Number of week in month: </h3>
<div *ngFor = "let title of data">
{{title.CREATE_TS | date:'dd/mm/yyyy'}}
<br/> Number of week in month is
{{title.CREATE_TS | date:'W'}}
</div>
To display the week of the year:
<div *ngFor = "let title of data">
{{title.CREATE_TS | date:'dd/mm/yyyy'}}
<br/> Number of week in year is
{{title.CREATE_TS | date:'w'}}
</div>
Sample TypeScript code:
data = [
{
CREATE_TS: "2018-08-15 17:17:30.0",
Key1: "Val1",
Key2: "Val2",
},
{
CREATE_TS: "2018-08-15 17:25:30.0",
Key1: "Val1",
Key2: "Val2",
},
{
CREATE_TS: "2018-08-15 17:28:30.0",
Key1: "Val1",
Key2: "Val2",
}
]
}