Search code examples
javascriptangularjsangularjs-ng-repeat

How to Iterate through array of Day Time and display only current week record


 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.


Solution

  • 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",
        }
      ]
    }