<h3>Auto Complete example of prime ng</h3>
<p>Start typing in dropdown or </p>
<ul>
<li> Start tying in drop-down with 3 chars. E.g: qui
<li> Click on dropdown arrow to get complete list
</ul>
<br>
<p *ngIf="options.length">
Results found: {{options.length}}
</p>
<p-autoComplete
[suggestions]="options"
(completeMethod)="filterMethod($event)"
[dropdown]="true"
field="title"
[multiple]="true"
[forceSelection]="true"
[minLength]="3"></p-autoComplete>
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
options = [];
constructor(public http: HttpClient) {
}
filterMethod(event) {
this.http.get('https://jsonplaceholder.typicode.com/todos')
.subscribe(res => {
const result = (<any>res).filter(option => option.title.includes(event.query));
console.log(result);
this.options = result;
});
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';
import { AutoCompleteModule } from 'primeng/autocomplete';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
imports: [ BrowserModule, FormsModule, AutoCompleteModule, HttpClientModule, BrowserAnimationsModule ],
declarations: [ AppComponent, HelloComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }