question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

markDisabled does not support instance method

See original GitHub issue

I’m not sure that is a bug or not, but try to access to this in the markDisabled callback failed:

  isWeekend(date: NgbDateStruct) {
    const d = new Date(date.year, date.month - 1, date.day);
    return d.getDay() === 0 || d.getDay() === 6;
  }

  isDisabled(date: NgbDateStruct, current: {month: number}) {
    const d = new Date(date.year, date.month - 1, date.day);
    return this.isWeekend(date); // this is undefined
  }

Bug description:

Link to minimally-working plunker that reproduces the issue:

http://plnkr.co/edit/sPAZc5vKszJZ0PsRQqIO?p=preview

Version of Angular, ng-bootstrap, and Bootstrap:

Angular: 4.0.3

ng-bootstrap: 1.0.0-alpha.26

Bootstrap:4.0.0-alpha.6

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wesleychocommented, May 18, 2017

I’m not sure anything can be done about this on the library side - if I remember right, this is sort of related to Angular itself and how it works with binding functions.

Your best bet would be to work around this by defining a function like

isDisabled = (date: NgbDateStruct, current: {month: number}) => {
    const d = new Date(date.year, date.month - 1, date.day);
    return this.isWeekend(date); // this is undefined
}

The benefit of this is that it preserves the context of this regardless of how Angular handles bound functions.

0reactions
ghostcommented, Nov 4, 2019

in template:

[markDisabled]=“isDisabled(allowedDays)”

in component

isDisabled(dates: NgbDateStruct[]) {
    return (pickerDate: NgbDateStruct, currentMonth) => {
        return !dates.find(dayAllowed => dayAllowed.year == pickerDate.year && dayAllowed.month == pickerDate.month && dayAllowed.day == pickerDate.day);
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ng Bootstrap date range picker [markDisabled] doesn't work ...
On your component.ts, I have made the following changes to your onDateSelection() method. This is not very elegant, but it does the job...
Read more >
error: formcontrolname must be used with a parent formgroup ...
This way, calling markPending(false) elsewhere (e.g. a different service validation call) will not prematurely mark this service call as "no longer pending".
Read more >
Datepicker - Angular powered Bootstrap
Using ngModel will allow you both to get and set selected value. The model, however, is NOT a native javascript date, see the...
Read more >
ionic2-calendar - npmfs
The text displayed when there's no event on the selected date in month view. ... you can call instance method 'loadEvents' event to...
Read more >
@ng-bootstrap/ng-bootstrap@14.0.0 - jsDocs.io
If true , panel content will be detached from DOM and not simply ... Returns the calendar service used in the specific datepicker...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found