Posted 8 April 2019, 5:33 pm EST
Side note: is this forum ever going to get the ability to edit/delete initial posts?
I found the “itemValidator” property, which seems to do what I want if I hard-code the days, but I’m having trouble getting it to work with my asynchronously loaded configuration. The validator is only running once, before the configuration loads, but somehow if I try to refresh the control after the configuration loads it says it isn’t defined yet.
HTML:
<div *ngIf="config">
<wj-input-date #dateElement [(value)]="myDate" [itemValidator]="disableDay"></wj-input-date>
</div>
TS:
@ViewChild("dateElement") dateElement: WjInputDate
config: any
myDate: Date
ngOnInit () {
// Config values come from Firebase
this.myService.getConfig().subscribe(config => {
this.config = config
// If I uncomment this, I get an error that dateElement is undefined
// this.dateElement.invalidate()
})
}
disableDay (date: Date): boolean {
// If I uncomment this, it works fine
// return ![0,6].includes(date.getDay())
// This is always undefined when it runs
console.log(this.config)
if (this.config) {
return !this.config.disableDays.includes(date.getDay())
} else {
return true
}
}