Skip to content

Commit

Permalink
fix: null-pointer exception if no form control directive on mat-select (
Browse files Browse the repository at this point in the history
#282)

* fix: null-pointer exception if no form control directive on mat-select

fixes #281

* fixup! fix: null-pointer exception if no form control directive on mat-select
  • Loading branch information
macjohnny authored Nov 17, 2020
1 parent 4873efd commit 4829ffd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 3.1.4
* Fix: null-pointer exception if no form control directive on `mat-select`
[#281](https://github.com/bithost-gmbh/ngx-mat-select-search/issues/281)

Thanks to @Daishy for reporting

## 3.1.3
* Fix: incorrect restoration of selection when using `[multiple]="true"`
[#279](https://github.com/bithost-gmbh/ngx-mat-select-search/issues/279)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "./node_modules/ng-packagr/package.schema.json",
"name": "ngx-mat-select-search",
"description": "Angular component providing an input field for searching / filtering MatSelect options of the Angular Material library.",
"version": "3.1.3",
"version": "3.1.4",
"license": "MIT",
"scripts": {
"ng": "ng",
Expand Down
10 changes: 9 additions & 1 deletion src/app/mat-select-search/mat-select-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { A, DOWN_ARROW, END, ENTER, ESCAPE, HOME, NINE, SPACE, UP_ARROW, Z, ZERO
import { ViewportRuler } from '@angular/cdk/scrolling';
import { LiveAnnouncer } from '@angular/cdk/a11y';
import { BehaviorSubject, combineLatest, Observable, of, Subject } from 'rxjs';
import { delay, filter, map, scan, startWith, switchMap, take, takeUntil, tap } from 'rxjs/operators';
import { delay, filter, map, startWith, switchMap, take, takeUntil, tap } from 'rxjs/operators';

import { MatSelectSearchClearDirective } from './mat-select-search-clear.directive';

Expand Down Expand Up @@ -553,6 +553,14 @@ export class MatSelectSearchComponent implements OnInit, OnDestroy, ControlValue
* Note: to improve this code, mat-select should be extended to allow disabling resetting the selection while filtering.
*/
private initMultipleHandling() {
if (!this.matSelect.ngControl) {
if (this.matSelect.multiple) {
// note: the access to matSelect.ngControl (instead of matSelect.value / matSelect.valueChanges)
// is necessary to properly work in multi-selection mode.
console.error('the mat-select containing ngx-mat-select-search must have a ngModel or formControl directive when multiple=true');
}
return;
}
// if <mat-select [multiple]="true">
// store previously selected values and restore them when they are deselected
// because the option is not available while we are currently filtering
Expand Down
2 changes: 1 addition & 1 deletion src/app/mat-select-search/ngx-mat-select-search.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { CommonModule } from '@angular/common';
import { MatSelectSearchClearDirective } from './mat-select-search-clear.directive';
import { ReactiveFormsModule } from '@angular/forms';

export const MatSelectSearchVersion = '3.1.2';
export const MatSelectSearchVersion = '3.1.4';


@NgModule({
Expand Down

0 comments on commit 4829ffd

Please sign in to comment.