selectItem
事件,例如:
(selectItem)="selected($event)"
:
selected($e) {
$e.preventDefault();
this.selectedItems.push($e.item);
this.inputEl.nativeElement.value = '';
}
一旦您在集合中获得了所选项目,就可以将其显示在输入字段之前:
<div class="form-control">
<span class="btn btn-primary btn-sm selected" *ngFor="let item of selectedItems">
{{item}}
<span class="close-selected" (click)="close(item)"> x</span>
</span>
<input #input type="text" class="input" [ngbTypeahead]="search" (selectItem)="selected($event)" autofocus placeholder="Select something..."/>
</div>
https://plnkr.co/edit/sZNw1lO2y3ZZR0GxLyjD?p=preview
另请参阅中的详细讨论
https://github.com/ng-bootstrap/ng-bootstrap/issues/532