-
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Directive to make "faster and easier" use of this component. #288
Comments
@andreElrico thanks for sharing the code. it would be great to include it in this repo, don't you think so? concerning your question: the code is necessary to set the initial selection. without it, the initial selection of the mat-select element will be empty |
I think thats something interessting, but I didnt yet include the |
@andreElrico thanks for the solution. Here is mine with a component instead of directive: interface Searchable {
id: string;
name: string;
}
@Component({
selector: 'app-select-search',
template: `
<ngx-mat-select-search
[formControl]="ctrl"
[placeholderLabel]="'mat-select-search:placeholder/label' | translate"
[noEntriesFoundLabel]="'mat-select-search:not-found/label' | translate">
<fa-icon ngxMatSelectSearchClear [icon]="clearSearchIcon"></fa-icon>
</ngx-mat-select-search>
`,
})
export class SelectSearchComponent<T extends Searchable> implements OnInit {
@Input() searchPool: T[];
clearSearchIcon = faTimes;
ctrl = new FormControl();
options: Observable<T[]>;
constructor(private matOption: MatOption) { }
ngOnInit(): void {
this.matOption.disabled = true; // otherwise ExpressionHasBeenChanged error
this.options = this.ctrl.valueChanges.pipe(
startWith(''),
map(value => {
if (!value) {
return this.searchPool;
}
const searchTerm = value.toLowerCase();
return this.searchPool.filter(item => item.name.toLowerCase().includes(searchTerm));
}),
);
}
} and it's easy to use just like <mat-option>
<app-select-search [searchPool]="views" #search></app-select-search>
</mat-option> However I don't anyhow feel this solution can be generalized. The way to search and other parameters such as i18n params are quite subjective. Probably this issue should be resolved as an example-like / documentation solution. |
I wrote a directive that makes it more convinient to use this component.
My Question: Everything seems to work. However: I did not include this piece of code yet: Where could this bite me ? I dont really know what thats doing to be honest:
https://stackblitz.com/edit/github-gtncrt?file=src%2Fapp%2Fexamples%2Fmat-select-auto.directive.ts
The text was updated successfully, but these errors were encountered: