You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to this typing, if I'd like to have ngbTypeahead working in some cases and disable it in the others, I have to either provide a noop function or use 2 different inputs in a template switched by *ngIf: one with the [ngbTypeahead] directive and another - without it.
Suppose, I have my own component which wraps an input with the [ngbTypeahead] directive:
<input type="text" [ngbTypeahead]="search"/>
My component must be able to support 2 modes: typeahead-enabled mode and just simple text input mode. Most natural way is to declare an undefune-able @Input like the below:
@Input()
public autoCompleteItemsFn: ((text: Observable<string>) => Observable<readonly unknown[]>) | undefined;
(where undefined means 'simple input mode') and bind the [ngbTypeahead] directive to it:
Improves "search" function typings by using standard rxjs `OperatorFunction` type and making search function optional
```ts
// before
@input() ngbTypeahead: (text: Observable<string>) => Observable<readonly any[]>;
// after
@input() ngbTypeahead: OperatorFunction<string, readonly any[]>| null | undefined;
```
Fixesng-bootstrap#3907
Improves "search" function typings by using standard rxjs `OperatorFunction` type and making search function optional
```ts
// before
@input() ngbTypeahead: (text: Observable<string>) => Observable<readonly any[]>;
// after
@input() ngbTypeahead: OperatorFunction<string, readonly any[]>| null | undefined;
```
Fixes#3907
Bug description:
Current declaration in
typeahead.d.ts
is:ngbTypeahead: (text: Observable<string>) => Observable<readonly any[]>;
i.e. a function must be provided at all times.
According to this typing, if I'd like to have
ngbTypeahead
working in some cases and disable it in the others, I have to either provide a noop function or use 2 differentinput
s in a template switched by*ngIf
: one with the[ngbTypeahead]
directive and another - without it.Suppose, I have my own component which wraps an
input
with the[ngbTypeahead]
directive:<input type="text" [ngbTypeahead]="search"/>
My component must be able to support 2 modes: typeahead-enabled mode and just simple text
input
mode. Most natural way is to declare anundefune
-able@Input
like the below:(where
undefined
means 'simpleinput
mode') and bind the[ngbTypeahead]
directive to it:<input type="text" [ngbTypeahead]="autoCompleteItemsFn"/>
Which perfectly worked before even if
autoCompleteItemsFn === undefined
.However. I can't do this anymore with strict templates due to incomplete typing.
Could you fix it by changing the typing as follows:
ngbTypeahead: (text: Observable<string>) => Observable<readonly any[]> | undefined;
?
Versions of Angular, ng-bootstrap and Bootstrap:
Angular: 10.2.3
ng-bootstrap: 7.0.0
Bootstrap: 4.5.3
The text was updated successfully, but these errors were encountered: