In my Angular2 app, I am utilizing Select2 and facing a challenge with accessing class properties in the data and processResults contexts. Unfortunately, these contexts do not belong to the class:
export class DefaultFormInputSelectComponent {
@Input() private validator;
private select2Options() {
return {
ajax: {
url: 'api',
dataType: 'json',
delay: 250,
data: this.ajaxData,
processResults: this.ajaxProcessResults
}
}
};
ajaxData = function(params) {
// The issue arises when trying to access variables not in the DefaultFormInputSelectComponent context
this.validator; // returns undefined, as it is not within the DefaultFormInputSelectComponent context
}
ajaxProcessResults = function(data) {
// The same issue persists as with ajaxData
}
}
Even after attempting to add context: this
in the ajax
property, the situation remains unchanged.