Angular PrimeNG Steps Events
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will see the Steps Events in Angular PrimeNG.
The Steps Component guides users through the steps of a task, i.e. it is used to indicate the step for completion of any specific task. Angular PrimeNG provides an event that is fired while opting for a new step.
Angular PrimeNG Steps Events:
- activeIndexChange: It is a callback that is fired when the new step is selected.
Syntax:
<p-steps [model]="items of the steps" (activeIndexChange)="function($event)"> ... </p-steps>
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 it using the following command.
cd appname
Step 3: Install PrimeNG in your given directory.
npm install primeng --save npm install primeicons --save
Project Structure: It will look like the following:
Example 1: This example describes the basic usage of the Steps Events in Angular PrimeNG.
- app.component.html
HTML
< div id = "GFG" > < h1 style = "color:green" > w3wiki </ h1 > < h2 >Angular PrimeNG Steps Events </ h2 > < div style = "width:80%;" > < p-steps [model]="data" [activeIndex]="activeIndex" [readonly]="false" (activeIndexChange)="print($event)"> </ p-steps > < p-toast position = "left" key = "left" > </ p-toast > </ div > </ div > |
- app.component.ts
Javascript
import { Component } from '@angular/core' ; import { ButtonModule } from 'primeng/button' ; import { MessageService } from 'primeng/api' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , providers: [MessageService], }) export class AppComponent { constructor( private messageService: MessageService ) { } title = 'GFG' ; activeIndex: number = 0; data = [ { label: 'I am Step 1' }, { label: 'I am Step 2' }, { label: 'I am Step 3' } ] public print(event: number) { this .messageService.add({ key: 'left' , severity: 'success' , summary: 'w3wiki' , detail: 'Hi Geek.. I am called when step is clicked' , }); } } |
- app.module.ts
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { AppComponent } from './app.component' ; import { StepsModule } from 'primeng/steps' ; import { RouterTestingModule } from "@angular/router/testing" ; import { ButtonModule } from 'primeng/button' ; import { ToastModule } from 'primeng/toast' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; @NgModule({ declarations: [ AppComponent, ], imports: [ BrowserModule, StepsModule, RouterTestingModule, ButtonModule, ToastModule, BrowserAnimationsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } |
Output:
Example 2: This is another example that describes the Angular PrimeNG Steps Events, where we will display an alert when activeIndexChange event occurs.
- app.component.ts
HTML
import { Component } from '@angular/core'; import { ButtonModule } from 'primeng/button'; @Component({ selector: 'app-root', templateUrl: './app.component.html', }) export class AppComponent { title = 'GFG'; activeIndex: number = 0; data = [ { label: 'I am Step 1' }, { label: 'I am Step 2' }, { label: 'I am Step 3' } ] public print(event: number) { window.alert("Hi Geek!!Active Index Changed "+ "Called for Step " + (event + 1)) } } |
- app.component.html
HTML
< div id = "GFG" > < h1 style = "color:green" > w3wiki </ h1 > < h2 >Angular PrimeNG Steps Events </ h2 > < div style = "width:80%;" > < p-steps [model]="data" [activeIndex]="activeIndex" [readonly]="false" (activeIndexChange)="print($event)"> </ p-steps > </ div > </ div > |
- app.module.ts
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { AppComponent } from './app.component' ; import { StepsModule } from 'primeng/steps' ; import { RouterTestingModule } from "@angular/router/testing" ; import { ButtonModule } from 'primeng/button' ; @NgModule({ declarations: [ AppComponent, ], imports: [ BrowserModule, StepsModule, RouterTestingModule, ButtonModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { } |
Output:
Reference: http://primefaces.org/primeng/steps/seat