From ca0be9b8a9628519bfb1a2ecaa19c3ff0a603682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ve=C4=8De=C5=99a?= Date: Mon, 8 Feb 2021 16:12:55 +0100 Subject: [PATCH] feat: allow nullish compareWith (#1857) There are 2 reasons to allow setting compareWith to null/undefined. 1. Reverting the set compareWith - possible the user of the ng-select might want to remove the previously set compareWith to allow default behaviour in combination with bindValue possibly. 2. Extensibility - we have a wrapper around the ng-select that provides custom styles, adds error messages. Not all use cases use compareWith, but some do. Now it is impossible to redirect the [compareWith] @Input without setting the default. That hinders the bindValue default behaviour. --- src/ng-select/lib/ng-select.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ng-select/lib/ng-select.component.ts b/src/ng-select/lib/ng-select.component.ts index 0ab5035df..9e1b46622 100644 --- a/src/ng-select/lib/ng-select.component.ts +++ b/src/ng-select/lib/ng-select.component.ts @@ -131,7 +131,7 @@ export class NgSelectComponent implements OnDestroy, OnChanges, AfterViewInit, C get compareWith() { return this._compareWith; } set compareWith(fn: CompareWithFn) { - if (!isFunction(fn)) { + if (fn !== undefined && fn !== null && !isFunction(fn)) { throw Error('`compareWith` must be a function.'); } this._compareWith = fn;