Ad

How To Iterate Through Array Of Day Time And Display Only Current Week Record

- 1 answer

 ng-repeat="day in task.DailyWorks | limitTo : weekdays.length: weekStart"

I am trying to iterate through daily work record in table columns, I want to display current week record first time. Then depends on user Click Previous week or Next week button it will change the records.

Ad

Answer

In Angular 2+ you can iterate using *ngFor. DatePipes of Week of Year and Week of Month are supported since Angular 7.

As Angular docs of DatePipe says:

Week of year: w

Week of month: W

An example at stackblitz

To show week of 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 show week of 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>

TypeScript:

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",
    }
  ]
}
Ad
source: stackoverflow.com
Ad