Open In App

Angular PrimeNG Steps Component

Last Updated : 28 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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 know how to use the Steps component in Angular PrimeNG. We will also learn about the properties, events & styling along with their syntaxes that will be used in the code. 

Step component: It is used to indicate or track the completion of series of processes.

Properties:

  • model: It is an array of menu items. It is of an array type of data & the default value is null.
  • activeIndex: It is the index of the active item. It accepts the number as an input data type & the default value is 0.
  • readonly: It specifies whether the items are clickable or not. It is of the boolean data type & the default value is true.
  • style: It sets the inline style of the component. It is of the string data type & the default value is null.
  • styleClass: It is the style class of the component. It is of the string data type & the default value is null.

Events:

  • activeIndexChange: it is a callback that is fired when the new step is selected.

 

Styling:

  • p-steps: It is the container element.
  • p-steps-item: It is the menuitem element.
  • p-steps-number: It is the number of menuitem.
  • p-steps-title: It is the label of menuitem.

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 is the basic example that illustrates how to use the Steps component.

app.component.html




<h2>GeeksforGeeks</h2>
<h4>PrimeNG Steps Component</h4>
<p-steps [model]="geeks" 
    [(activeIndex)]="gfg" [readonly]="false">
</p-steps>


app.component.ts




import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  geeks: MenuItem[];
  gfg: number = 1;
  
  ngOnInit() {
    this.geeks = [
      { label: "PrimeNG" },
      { label: "AngularJS" },
      { label: "ReactJS" },
      { label: "HTML" },
    ];
  }
}


app.module.ts




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
  
import { AppComponent } from "./app.component";
import { StepsModule } from "primeng/steps";
import { ToastModule } from "primeng/toast";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    StepsModule,
    ToastModule,
    RouterModule.forRoot([{ path: ""
        component: AppComponent }]),
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}


Output:

Example 2: In this example, we will make the next button to navigate the element in the Step Component.

app.component.html




<h2>GeeksforGeeks</h2>
<h4>PrimeNG Steps Component</h4>
<p-steps
  [model]="[
    { label: 'DSA' },
    { label: 'Algorithm' },
    { label: 'Web Tech' },
    { label: 'Aptitude' }
  ]"
  [(activeIndex)]="gfg"
  [readonly]="true">
</p-steps><br />
<button (click)="chan()">Next</button>


app.component.ts




import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  geeks: MenuItem[];
  gfg: number = 0;
  
  chan() {
    this.gfg += 1;
  }
  ngOnInit() {}
}


app.module.ts




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
  
import { AppComponent } from "./app.component";
import { StepsModule } from "primeng/steps";
import { ToastModule } from "primeng/toast";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    StepsModule,
    ToastModule,
    RouterModule.forRoot([{ path: ""
        component: AppComponent }]),
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}


Output:

Reference: https://primefaces.org/primeng/showcase/#/steps/confirmation



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads