angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.29k stars 6.73k forks source link

dateOptions calling outside function; #6618

Closed xavidram closed 5 years ago

xavidram commented 7 years ago

Not sure if this is already a feature but I would like some insite first. I simply want to call a function within he function call inside dateOptions.

dateOptions dateOptions = { dateDisabled: this.disabledDates, formatYear: 'yy', maxDate: new Date(2020, 5, 22), minDate: new Date(), startingDate: 1 }; Disabled Dates Function: disabledDates(data) { // Check if date is in the array if(this.FullDays) { if(this.FullDays.indexOf(data.date.getFullYear() + '-' + (data.date.getMonth() + 1) + '-' + data.date.getDate()) !== -1) { console.log('gocha'); return true; } } // otherwise check if it s a weekend return data.mode === 'day' && (data.date.getDay() === 0 || data.date.getDay() === 6); }

External function setting scope variable. getFullDays() { // Query DB for dates to be disabledDates this.FullDays = this.proctoringService.getFullDays({id: this.location._id, uid: this.location.seats}); }

The idea is I set additional disabled dates besides weekends by calling a service the queries information I have in a database. Then I check inside the disabled dates function if the date being looked at is either a weekend or in the array of predefined dates. If it is, disable the date, otherwise it doesn't. The issue is that I cannot call scope functions from within the disabledDates function called within dateOptions, nor can I use variables defined within the scope. They are all undefined within disabledDates.

I wanted to know if there is a workaround or something I am missing in order to access these variables.

Angular: 1.6.0

UIBS: 2.0.1

Bootstrap: 3.3.7