angularngb-datepicker

Angular ngbDatepicker: How to include context in markDisabled


I have an input field defined as ngbDatepicker. Some of the days should be disabled which is why I use [markDisabled]="getDisabledDays" like this:

<input type="text" [minDate]="getMinDate()"
        [maxDate]="maxDate" formControlName="deliverydate" #d="ngbDatepicker" 
        [markDisabled]="getDisabledDays" (click)="d.toggle()" required>
    
    
    getDisabledDays = function (date: NgbDate, current: { month: number }) {
       //returns hardcoded NgbDateStruct[] array with the days.
    }

Till now I had an hardcoded NgbDateStruct[] with the disabled days. I now want to fill that array dynamically which is why I have to access the components context by using "this". However, "this" is undefined in the functions scope and I cant access the properties I need. How can I solve that?


Solution

  • SOLUTION:

    As suggested by Eliseo:

    getDisabledDays = (date: NgbDate, current: { month: number })=> { console.log(this.days)}

    The reason is, that the arrow function binds this to the context where it is first defined, which is the class context.