Open In App

Angular PrimeNG Form AutoComplete Animation Configuration Component

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that helps to create an attractive user interface with enhanced functionality. These components can be utilized for great styling & are used to make responsive websites with very much ease. In this article, we will see the Form AutoComplete Animation Configuration Component in Angular PrimeNG.

Animation Configuration Component is used to set the transition time of the animation and the transition of the show and hide animations can be customized using the showTransitionOptions and hideTransitionOptions properties.



Angular PrimeNG Form AutoComplete Animation Configuration Properties:

Syntax:



<p-autoComplete 
    [showTransitionOptions]="'...'" 
    [hideTransitionOptions]="'...'">
</p-autoComplete>

Creating Angular application & module installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to the current working directory where the new app just has been created, by using the following command:

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: After successful installation, it will look like the following image:

 

ng serve --save

Example 1: This code example demonstrates the use of the Form AutoComplete Animation Configuration Component in Angular PrimeNG.




<div style="text-align:center">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h3>A computer science portal for geeks</h3>
    <h4>
        Angular PrimeNG Form AutoComplete Animation
        Configuration Component
    </h4>
    <p-autoComplete [(ngModel)]="selectedCourse" 
                    [suggestions]="filteredsub"
                    (completeMethod)="course($event)" 
                    [showTransitionOptions]="'1500ms'" 
                    field="name" 
                    [minLength]="1">
    </p-autoComplete>
</div>




import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
import { SelectItem } from 'primeng/api';
import { SelectItemGroup } from 'primeng/api';
import { FilterService } from 'primeng/api';
import { gfgService } from './gfgservice';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [gfgService, FilterService],
})
export class AppComponent {
    subject: any[];
    filteredsub: any[];
    selectedCourse: any[];
    filteredGroups: any[];
  
    constructor(private gfg: gfgService, 
                private filterService: FilterService) { }
  
    ngOnInit() {
        this.gfg.getCourse().then((course) => {
            this.subject = course;
        });
    }
  
    course(event) {
        let filtered: any[] = [];
        let query = event.query;
        for (let i = 0; i < this.subject.length; i++) {
            let subject = this.subject[i];
            if (subject.name.toLowerCase().indexOf(query.toLowerCase()) == 0) {
                filtered.push(subject);
            }
        }
        this.filteredsub = filtered;
    }
}




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { AutoCompleteModule } from 'primeng/autocomplete';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        AutoCompleteModule,
        FormsModule,
        HttpClientModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule { }




import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
  
@Injectable()
export class gfgService {
    constructor(private http: HttpClient) { }
  
    getCourse() {
        return this.http
            .get < any > ('assets/course.json')
                .toPromise()
                .then((res) => <any[] > res.data)
                .then((data) => {
                    return data;
                });
    }
}




{
  "data": [
    { "name": "DSA" },
    { "name": "C++" },
    { "name": "HTML" },
    { "name": "JAVA" },
    { "name": "Python" },
    { "name": "Operating System" },
    { "name": "Computer Networks" }
  ]
}

Output:

 

Example 2: This is another example that demonstrates the use of the Form AutoComplete Animation Configuration Component in Angular PrimeNG.




<div style="text-align:center">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h3>A computer science portal for geeks</h3>
    <h4>
        Angular PrimeNG Form AutoComplete 
        Animation Configuration Component
    </h4>
    <p-autoComplete [(ngModel)]="selectedCourse" 
                    [suggestions]="filteredsub" 
                    (completeMethod)="course($event)" 
                    [hideTransitionOptions]="'1500ms'" 
                    field="name" 
                    [minLength]="1">
    </p-autoComplete>
</div>




import { Component } from '@angular/core';
import { MenuItem } from 'primeng/api';
import { SelectItem } from 'primeng/api';
import { SelectItemGroup } from 'primeng/api';
import { FilterService } from 'primeng/api';
import { gfgService } from './gfgservice';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  providers: [gfgService, FilterService],
})
export class AppComponent {
  subject: any[];
  filteredsub: any[];
  selectedCourse: any[];
  filteredGroups: any[];
  
  constructor(private gfg: gfgService, 
    private filterService: FilterService) {}
  
  ngOnInit() {
    this.gfg.getCourse().then((course) => {
      this.subject = course;
    });
  }
  
  course(event) {
    let filtered: any[] = [];
    let query = event.query;
    for (let i = 0; i < this.subject.length; i++) {
      let subject = this.subject[i];
      if (subject.name.toLowerCase().indexOf(query.toLowerCase()) == 0) {
        filtered.push(subject);
      }
    }
    this.filteredsub = filtered;
  }
}




import { NgModule } from '@angular/core';
import { BrowserModule } 
  from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule } 
  from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { AutoCompleteModule } from 'primeng/autocomplete';
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    AutoCompleteModule,
    FormsModule,
    HttpClientModule
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
  
export class AppModule { }




import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
  
@Injectable()
export class gfgService {
  constructor(private http: HttpClient) { }
  
  getCourse() {
    return this.http
      .get < any > ('assets/course.json')
        .toPromise()
        .then((res) => <any[] > res.data)
        .then((data) => {
          return data;
        });
  }
}




{
  "data": [
    { "name": "DSA" },
    { "name": "C++" },
    { "name": "HTML" },
    { "name": "JAVA" },
    { "name": "Python" },
    { "name": "Operating System" },
    { "name": "Computer Networks" }
  ]
}

Output:

 

Reference: https://www.primefaces.org/primeng/autocomplete


Article Tags :