-
Notifications
You must be signed in to change notification settings - Fork 42
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
Support the functionality to add dynamic options #21
Comments
Just change the items property and it is must to be enough. |
how can I change the items property? |
import {Component} from '@angular/core';
@Component({
selector: 'single-demo',
template: `<ngx-select [items]="items"></ngx-select>`
})
export class SingleDemoComponent {
public items: string[] = [];
private counter = 1;
constructor() {
setTimeout(() => {
setInterval(() => {
this.items.push('item ' + this.counter++);
}, 2000);
}, 2000);
}
} |
Nice. but when I can't find the option, how can I hook this? |
Are you talking about a something event firing on a search text is typed and the rendered item list is empty? |
Yep |
I think that I can add the event interface INgxSelectOption {
value: number | string;
text: string;
disabled: boolean;
} |
Thank you very much. I should use this plugin. Excuse me, but can you make a plunkr for this? |
By the way, when I use this plugin with Angular Material, how should I do for? |
Yes. Sure. Make a plankr. It will help me to understand your case. |
Currently, I have no experience with Angular Material and I am not sure about it is working correctly. |
@optimistex I am sorry, but I am not familiar with Angular Material, and I am in a busy condition with my client's work. so I am afraid that I can't help you now. |
Okay. Do not worry. |
I have the similar case in my the general project. Look at the trouble:
Solution!We have to send a search request for all typed text, but with debounce(!). For clarity look at the real code from my project: <ngx-select class="ls-select" id="position-name" [formControl]="searchPosControl"
[items]="subjSearchPosItems | async" optionValueField="uuid" optionTextField="name"
(typed)="searchPosTyped.next($event)"
placeholder="Поиск позиции"
[allowClear]="true">
</ngx-select> export class PageOrderEditComponent {
// ...........
public searchPosTyped = new Subject<string>();
public searchPosControl = new FormControl();
public subjSearchPosItems: Observable<INomenclaturePosition[]>;
// ...........
private initBehaviorsOfAddPosition() { // called from the constructor
// for live search in searchPosControl
this.subjSearchPosItems = this.searchPosTyped
.debounceTime(500)
.flatMap((text: string) => this.catalog.getNomenclaturePositionList({search: text}))
.flatMap((itemList: ICrudList<INomenclaturePosition>) => Observable.from(itemList.items)
.map((item: INomenclaturePosition) => Object.assign({name: item.values.f_name}, item))
.toArray()
)
.share();
// .............
}
} |
Awesome! |
Thank you very much! |
@optimistex Using the solution from your comment only loads 100 results, would it be possible to load more when scrolling to the bottom of the dropdown (as in select2)? |
@TFeld00 I think it's possible. I can make an event with parameters item, index, items. What do you think about the idea? |
@optimistex Sounds good :) |
@TFeld00 Well. I'll implement it a little later. |
@optimistex No problem, I'll see if i can work around it atm |
It's done: https://github.com/optimistex/ngx-select-ex/releases/tag/3.3.11
|
I can't add not existed option, does this package support the dynamic option population?
The text was updated successfully, but these errors were encountered: