Skip to content

Commit

Permalink
fix: Not working with custom getter #19
Browse files Browse the repository at this point in the history
  • Loading branch information
optimistex committed Feb 10, 2018
1 parent 45cddf6 commit 0710e0e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/app/lib/ngx-select/ngx-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ enum ENavigation {
first, previous, next, last
}

function propertyExists(obj: Object, propertyName: string) {
return propertyName in obj;
}

@Component({
selector: 'ngx-select',
templateUrl: './ngx-select.component.html',
Expand Down Expand Up @@ -425,7 +429,7 @@ export class NgxSelectComponent implements ControlValueAccessor, DoCheck, AfterC
let option: NgxSelectOption;
data.forEach((item: any) => {
const isOptGroup = typeof item === 'object' && item !== null &&
item.hasOwnProperty(this.optGroupLabelField) && item.hasOwnProperty(this.optGroupOptionsField) &&
propertyExists(item, this.optGroupLabelField) && propertyExists(item, this.optGroupOptionsField) &&
Array.isArray(item[this.optGroupOptionsField]);
if (isOptGroup) {
const optGroup = new NgxSelectOptGroup(item[this.optGroupLabelField]);
Expand All @@ -449,10 +453,10 @@ export class NgxSelectComponent implements ControlValueAccessor, DoCheck, AfterC
value = text = data;
disabled = false;
} else if (typeof data === 'object' && data !== null &&
(data.hasOwnProperty(this.optionValueField) || data.hasOwnProperty(this.optionTextField))) {
value = data.hasOwnProperty(this.optionValueField) ? data[this.optionValueField] : data[this.optionTextField];
text = data.hasOwnProperty(this.optionTextField) ? data[this.optionTextField] : data[this.optionValueField];
disabled = data.hasOwnProperty('disabled') ? data['disabled'] : false;
(propertyExists(data, this.optionValueField) || propertyExists(data, this.optionTextField))) {
value = propertyExists(data, this.optionValueField) ? data[this.optionValueField] : data[this.optionTextField];
text = propertyExists(data, this.optionTextField) ? data[this.optionTextField] : data[this.optionValueField];
disabled = propertyExists(data, 'disabled') ? data['disabled'] : false;
} else {
return null;
}
Expand Down

0 comments on commit 0710e0e

Please sign in to comment.