Angular PrimeNG的steps属性

Angular PrimeNG的steps属性

Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,这个框架可用于制作响应式网站,非常容易。在这篇文章中,我们将学习如何在Angular PrimeNG中使用steps属性。我们还将了解这些属性,以及它们在代码中的语法。

步骤组件用于指示或跟踪一系列过程的完成情况。

Angular PrimeNG steps属性:

  • model。它是一个菜单项的数组。它是一个数组类型的数据,默认值为空。
  • activeIndex。它是活动项目的索引。它接受数字作为输入数据类型,默认值为0。
  • readonly: 它指定了项目是否可以被点击。它是布尔数据类型,默认值为真。
  • style。它设置组件的内联风格。它的数据类型为字符串,默认值为空。
  • styleClass。它是组件的风格类。它的数据类型为字符串,默认值为空。

创建Angular应用程序和模块安装。

第1步:使用以下命令创建一个Angular应用程序。

ng new appname

第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。

cd appname

第3步在你给定的目录中安装PrimeNG。

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

项目结构:它将看起来像如下。

Angular PrimeNG的步骤属性

运行应用程序的步骤:运行以下命令以查看输出。

ng serve --open

例子1:下面是说明使用Angular PrimeNG steps属性的例子代码。

  • app.component.html:
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Steps Properties</h4>
<p-steps
    [model]="[
        { label: 'DSA' },
        { label: 'Algorithm' },
        { label: 'Web Tech' },
        { label: 'Aptitude' }
    ]"
    [(activeIndex)]="gfg"
    [readonly]="false">
</p-steps><br />
<button (click)="chan()">----></button>
  • app.component.ts:
import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
    selector: "app-root",
    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 {}

输出:

Angular PrimeNG的步骤属性

示例2:下面是另一个示例代码,说明了使用readonly="true"的Angular PrimeNG steps属性的使用。

  • app.component.html:
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Steps Properties</h4>
<p-steps
    [model]="[
        { label: 'DSA' },
        { label: 'Algorithm' },
        { label: 'Web Tech' },
        { label: 'Aptitude' }
    ]"
    [(activeIndex)]="gfg"
    [readonly]="true">
</p-steps><br />
  • app.component.ts:
import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
})
export class AppComponent {
    geeks: MenuItem[];
    gfg: number = 1;
  
    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 {}

输出:

Angular PrimeNG的步骤属性

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程